博文
happy 2004(2007-02-22 10:30:00)
摘要:#include<iostream>using namespace std;
int left2[29],left3[29],left167[29];
int left(int i,double x){ if(x>28) x=x-(int)(x/28)*28; switch (i) { case 2: return left2[(int)x-1]; case 3: return left3[(int)x-1]; case 167:return left167[(int)x-1]; } return 0;}
int happy2004(double x){ if(x>28) x=x-(int)(x/28)*28; if(x==1) return 6; else { int n1=0,n2=0,n3=0,n4=0,n5=0,cash1=0,cash2=0; cash1=(29-((left(3,x+1)-1)*14)%29)%29; cash2=(29-(left(167,x)-1)*11%29)%29; n1=((left(2,2*x+1)-1)*cash1*left(167,x))%29; n2=(left(2,2*x-1)*cash1*cash2)%29; n3=(2*n2)%29; n4=(left(3,x)*(left(2,2*x-1)-1)*cash2)%29; n5=happy2004(x-1); return (n1+n2+n3+n4+n5)%29; }}
int main(int argc, char* argv[]){ int i2=2,i3=3,i167=22; double n; &......
Number Triangle(2007-02-21 20:31:00)
摘要:Consider the number triangle shown below. Write a program that calculates the highest sum of numbers that can be passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
In the sample above, the route from 7 to 3 to 8 to 7 to 5 produces the highest sum: 30.
Input
There are multiple test cases.The first line of each test case contains R (1 <= R <= 1000), the number of rows. Each subsequent line contains the integers for that particular row of the triangle. All the supplied integers are non-negative and no larger than 100.
Output
Print a single line containing the largest sum using the traversal specified for each test case.
Sample Input5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output30
Original: IOI 95
#include<iostream>using namespace std;
int maxn(int a,int b......
ACM代码库(2007-02-18 23:14:00)
摘要:STL非修改算法
由于STL算法都是通过迭代器间接处理容器,下面定义istream_iteratorInIt,ostream_itreatorOutIt,forward_iteratorFwdIt,bidirectional_iterator BidIt,random_iterator RanIt
非修改算法:
算法
用法
说明
adjacent_find
FwdIt adjacent_find(FwdIt first,FwdIt last);FwdIt adjacent_find(FwdIt first,FwdIt last,Pred pr);
在[first,last)查找相同元素的首次出现或能使pr(elem,nextElem)为true的元素的位置 ,函数查找成功返回位置,失败返回last
binary_search
bool binary_search(FwdIt first,FwdIt last,const T& val);bool binary_search(FwdIt first,FwdIt last,const T& val,Pred pr);
在区间[first,last)中查找元素val,如果找到返回true,否则返回false,第二种形式pr用于设定查找准则
count
size_t count(InIt first,InIt last,const T& val);
返回区间[first,last)上val出现的次数
count_if
size_t count_if(InIt first,InIt last,Pred pr);
返回区间[first,last)上满足条件pr(elem)的元素个数
equal
bool equal(InIt1 first,InIt1 last,InIt2 x);bool equal(InIt1 first,InIt1 last,InIt2 x,Pred pr);
判断[first,last)与x开始的区间的元素是否相等,pr用于指定判断函数
equal
pair<FwdIt,FwdIt> equal_range(FwdIt f......
扫雷游戏(2007-02-13 17:11:00)
摘要:扫雷是Windows自带的游戏。游戏的目标是尽快找到雷区中的所有地雷,而不许踩到地雷。如果方块上的是地雷,将输掉游戏。如果方块上出现数字,则表示在其周围的八个方块中共有多少颗地雷。
你的任务是在已知地雷出现位置的情况下,得到各个方块中的数据。 *...
.... “*”表示有地雷
.*.. “.”表示无地雷
....
经过处理应得到 *100
2210
1*10
1110
输入
输入有多组数据,每组数据的第一行有两个数字,m,n(0<m,n<100)表示游戏中雷区的范围为m×n。接下来m行每行有n个字符。“*” 表示有地雷,“.”表示无地雷。最后一组数据m=0,n=0表示输入结束,不需要处理。
输出
对于每组输入数据,输出结果,各方块数字间不留空格。每组结果之后有一个空行。
输入样例2 3
***
...
4 4
*...
....
.*..
....
0 0
输出样例***
232
*100
2210
1*10
1110
Original: FZUPC Warmup 2005
#include<iostream>using namespace std;
void do_with(char n[][100],int a,int b){ int i,j,k,h; for(i=0;i<a;i++) for(j=0;j<b;j++) if(n[i][j]=='*') { for(k=i-1;k<=i+1;k++) for(h=j-1;h<=j+1;h++) if(k<a&&k>=0&&h>=0&&h<b&&n[k][h]!='*')n[k][h]++; }}
int main(){ &nbs......
做减法(2007-02-12 17:55:00)
摘要:乐乐今天刚学减法,老师布置了好多关于减法的家庭作业题。乐乐可不想把时间都浪费在这重复机械的题目上。你能帮帮她吗?
输入输出格式输入数据由多组数据组成。每组数据只有一行,包含两个整数,用空格分开。对于每组数据,输出一行,包含两个整数的差。如果数字超过3位,应从最低位起,按每三位分组。题目所有输入输出保证在[-2^31, 2^31-1]范围内。
样例输入2000 1000
样例输出1,000
Original: FZUPC 2006
#include<iostream>#include<cstring>using namespace std;
void int_to_c(long int a){ long int i,j,k=0,flag=0; char x[20]; if(a<0){a*=-1;flag=-1;} for(i=0;a!=0;i++) {//整数转换为字符串 x[i]=a%10+48; a/=10; } x[i]='\0'; if(flag==-1)cout<<"-"; for(j=i-1,flag=strlen(x)%3;j>=0;j--) { cout<<x[j]; if(flag>0) {//处理对3位取余不为0的情况 flag--; if(flag==0){flag=-1;cout<<",";continue;} } if(flag<=0) {//处理后面位数对3......
HangOver(2007-02-12 15:21:00)
摘要:How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will c......
阅读顺序(2007-02-12 15:19:00)
摘要:大多数语言是从左向右读的。但是,在一些语言中,阅读顺序是从右向左读的。这给语言交流增加了不少的麻烦。现在,请你编写一个程序,能够将一从左到右书写的文字自动转成从右向左的顺序。
输入
输入的第一行是一个数字n(n<100),接下来的有n行的文字,由字母、空格、数字以及各种标点组成,每行文字长度不超过200个字符。
输出
将输入的文字转成从右向左的顺序,一行输入对应一行输出。
输入样例3
a man a plan a canal panama
Frankly, I don't think we'll make much
OK?
输出样例amanap lanac a nalp a nam a
hcum ekam ll'ew kniht t'nod I ,ylknarF
?KO
解释
如果不考虑词与词之间的空格,第一句话从左向右读和从右向左读的结果是一样的:-)
Original: FZUPC Warmup 2005
#include<iostream>#include<cstring>using namespace std;int main(){ char c[100][200]; char str[200]; int n,j,i; cin>>n; cin.getline(str,200); for(i=0;i<n;i++) cin.getline(c[i],200); for(i=0;i<n;i++) { for(j=strlen(c[i])-1;j>=0;j--) cout<<c[i][j]; cout<<endl; } return 0;}......
