选拔赛的题目,当时没看见,其实挺水的,但是我没有全部做出来、、、还是水平太渣啊、、
1sting
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3477 Accepted Submission(s): 1347
Problem Description
You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get.
Input
The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200.
Output
The output contain n lines, each line output the number of result you can get .
Sample Input
3 1 11 11111
Sample Output
1 2 8
Author
z.jt
这是一道简单的规律题,其实一看就知道是斐波那契数列,但是、、一开始用int 然后用__int64 WA了两发,这就是本题的坑点,所以就要用到大数加法啦、、、
Total Submission(s): 1097 Accepted Submission(s): 239
这题我还没搞出来,题意是这样的,告诉你一些矩形的坐标,然后叫你求,最后这些矩形所占有的面积是多大,一开始以为是前几天JJ 讲的容斥原理什么的,不敢写,然后又看到数据才1000 * 1000 ,打算暴力过一遍、、、 于是、、、就有这样的思路:每输入一个矩形,把它所在的单位方形标记,并进行计数处理
我觉得我的思路好清晰,可是就是wa ,亏我还在debug 上花了那么多的时间, 如果哪位有兴趣,可以帮我看一下啊 - - # 感激不尽
Total Submission(s): 4542 Accepted Submission(s): 1176
简单的KMP,呃,因为忘了,敲了许久、、
Total Submission(s): 4763 Accepted Submission(s): 1928
一开始以为是很高深的并查集, 然后,它是一道很水,很弱的最短路,因为数据很小,所以就用floyd 了,毕竟最简便
Total Submission(s): 5069 Accepted Submission(s): 3091
最水的一道题,还是中文的,简单模拟。
Total Submission(s): 1252 Accepted Submission(s): 577
这是一道简单的规律题,其实一看就知道是斐波那契数列,但是、、一开始用int 然后用__int64 WA了两发,这就是本题的坑点,所以就要用到大数加法啦、、、
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; char s[210]; int tt[210][1010]; // 存答案 int lenth[1010]; // 代表长度 void solve() { int i,j,k,l,m; memset(tt,0,sizeof(tt)); tt[1][0] = 1; tt[2][0] = 2; lenth[1] = lenth[2] = 1; l = 0; for(i = 3; i < 210; i ++) { k = 0; for(j = 0; j <= lenth[i - 1]; j ++) { l = k + tt[i-1][j] + tt[i - 2][j]; tt[i][j] = l % 10; k = l / 10; } if(tt[i][lenth[i - 1]]) lenth[i] = lenth[i - 1] + 1; else lenth[i] = lenth[i - 1]; } } int main() { solve(); int n; /*for(int i = 0; i < 200; i ++) { printf("%d : %d\n",i, lenth[i]); }*/ while(~scanf("%d",&n)) { while(n --) { scanf("%s", s); int len = strlen(s); for(int i = lenth[len] - 1; i >= 0; i --) { //if(tt[len][i] != 0) printf("%d",tt[len][i]); } printf("\n"); } } }
A + B forever!
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1097 Accepted Submission(s): 239
Problem Description
As always, A + B is the necessary problem of this warming-up contest. But the patterns and contents are different from the previous ones. Now I come up with a new “A + B” problem for you, the top coders of HDU.
As we say, the addition defined between two rectangles is the sum of their area . And you just have to tell me the ultimate area if there are a few rectangles.
Isn’t it a piece of cake for you? Come on! Capture the bright “accepted” for yourself.
As we say, the addition defined between two rectangles is the sum of their area . And you just have to tell me the ultimate area if there are a few rectangles.
Isn’t it a piece of cake for you? Come on! Capture the bright “accepted” for yourself.
Input
There come a lot of cases. In each case, there is only a string in one line. There are four integers, such as “(x1,y1,x2,y2)”, describing the coordinates of the rectangle, with two brackets distinguishing other rectangle(s) from the string. There lies a plus symbol between every two rectangles. Blanks separating the integers and the interpunctions are added into the strings arbitrarily. The length of the string doesn’t exceed 500.
0<=x1,x2<=1000,0<=y1,y2<=1000.
0<=x1,x2<=1000,0<=y1,y2<=1000.
Output
For each case, you just need to print the area for this “A+B” problem. The results will not exceed the limit of the 32-signed integer.
Sample Input
(1,1,2,2)+(3,3,4,4) (1,1,3,3)+(2,2,4,4)+(5,5,6,6)
Sample Output
2 8
Author
Wang Ye
这题我还没搞出来,题意是这样的,告诉你一些矩形的坐标,然后叫你求,最后这些矩形所占有的面积是多大,一开始以为是前几天JJ 讲的容斥原理什么的,不敢写,然后又看到数据才1000 * 1000 ,打算暴力过一遍、、、 于是、、、就有这样的思路:每输入一个矩形,把它所在的单位方形标记,并进行计数处理
我觉得我的思路好清晰,可是就是wa ,亏我还在debug 上花了那么多的时间, 如果哪位有兴趣,可以帮我看一下啊 - - # 感激不尽
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int vis[1010][1010]; char tt[510]; int main() { int a[5]; while(gets(tt)) { memset(vis, 0, sizeof(vis)); memset(a, 0, sizeof(a)); int cnt = 1; // 用来判断是否已经输入四个坐标 int len = strlen(tt); int ans = 0; for(int i = 1; i < len; i ++) { if(!(tt[i] >= '0' && tt[i] <= '9')) continue; while(tt[i] >= '0' && tt[i] <= '9') { a[cnt] = a[cnt] * 10 + (tt[i] - '0'); i ++; } cnt ++; if(cnt == 5) { cnt = 1; for(int j = a[1] + 1; j <= a[3]; j ++) { for(int k = a[2] + 1; k <= a[4]; k ++) { if(!vis[j][k]) { vis[j][k] = 1; // 单位小方形进行标记,并计数 ans ++; } } } memset(a, 0, sizeof(a)); // i --; //continue; } } printf("%d\n", ans); } }
A + B for you again
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4542 Accepted Submission(s): 1176
Problem Description
Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between them is “asdfg”, for “sdf” is the tail substring of “asdf” and the head substring of the “sdfg” . However, the result comes as “asdfghjk”, when you have to add “asdf” and “ghjk” and guarantee the shortest string first, then the minimum lexicographic second, the same rules for other additions.
Input
For each case, there are two strings (the chars selected just form ‘a’ to ‘z’) for you, and each length of theirs won’t exceed 10^5 and won’t be empty.
Output
Print the ultimate string by the book.
Sample Input
asdf sdfg asdf ghjk
Sample Output
asdfg asdfghjk
Author
Wang Ye
简单的KMP,呃,因为忘了,敲了许久、、
#include<cstdio> #include<algorithm> #include<string.h> using namespace std; #define MAX 500010 char str1[MAX]; char str2[MAX]; int next[MAX]; void get_next(char *p) { int i = 0,j = -1; next[0] = -1; int len = strlen(p); while(i < len) { if(j == -1 || p[i] == p[j]) { i++; j++; next[i] = j; } else j = next[j]; } } int KMP(char *s,char *t) { int len1 = strlen(s); int len2 = strlen(t); int i = 0, j = 0; get_next(t); while(i < len1 && j < len2) { if(j == -1 || s[i] == t[j]) { i ++; j ++; } else j = next[j]; } if(i == len1) return j; return 0; } int main() { int n, m; while(~scanf("%s%s",str2, str1)) { int t = KMP(str1, str2); int tt = KMP(str2, str1); if(t == tt) { if(strcmp(str1, str2) < 0) { printf("%s%s\n", str1, str2 + t); } else printf("%s%s\n",str2, str1 + t); } else if(t > tt) { printf("%s%s\n", str1, str2 + t); } else printf("%s%s\n",str2, str1 + tt); } return 0; }
六度分离
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4763 Accepted Submission(s): 1928
Problem Description
1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人就可以将他们联系在一起,因此他的理论也被称为“六度分离”理论(six degrees of separation)。虽然米尔格兰姆的理论屡屡应验,一直也有很多社会学家对其兴趣浓厚,但是在30多年的时间里,它从来就没有得到过严谨的证明,只是一种带有传奇色彩的假说而已。
Lele对这个理论相当有兴趣,于是,他在HDU里对N个人展开了调查。他已经得到了他们之间的相识关系,现在就请你帮他验证一下“六度分离”是否成立吧。
Lele对这个理论相当有兴趣,于是,他在HDU里对N个人展开了调查。他已经得到了他们之间的相识关系,现在就请你帮他验证一下“六度分离”是否成立吧。
Input
本题目包含多组测试,请处理到文件结束。
对于每组测试,第一行包含两个整数N,M(0<N<100,0<M<200),分别代表HDU里的人数(这些人分别编成0~N-1号),以及他们之间的关系。
接下来有M行,每行两个整数A,B(0<=A,B<N)表示HDU里编号为A和编号B的人互相认识。
除了这M组关系,其他任意两人之间均不相识。
对于每组测试,第一行包含两个整数N,M(0<N<100,0<M<200),分别代表HDU里的人数(这些人分别编成0~N-1号),以及他们之间的关系。
接下来有M行,每行两个整数A,B(0<=A,B<N)表示HDU里编号为A和编号B的人互相认识。
除了这M组关系,其他任意两人之间均不相识。
Output
对于每组测试,如果数据符合“六度分离”理论就在一行里输出"Yes",否则输出"No"。
Sample Input
8 7 0 1 1 2 2 3 3 4 4 5 5 6 6 7 8 8 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 0
Sample Output
Yes Yes
Author
linle
一开始以为是很高深的并查集, 然后,它是一道很水,很弱的最短路,因为数据很小,所以就用floyd 了,毕竟最简便
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int inf = 0x3f3f3f3f; int mpt[210][210]; int n, m; void init(int x) { for(int i = 0; i < x; i ++) { for(int j = 0; j <= i; j ++) { if(i == j) mpt[i][j] = 0; else mpt[i][j] = mpt[j][i] = inf; } } } int main() { int a, b; while(~scanf("%d%d",&n, &m)) { init(n); for(int i = 0; i < m; i ++) { scanf("%d%d",&a, &b); mpt[a][b] = mpt[b][a] = 1; } for(int k = 0; k < n; k ++) { for(int i = 0; i < n; i ++) { for(int j = 0; j < n; j ++) mpt[i][j] = min(mpt[i][j], mpt[i][k] + mpt[k][j]); } } int ok = 1; for(int i = 0; i < n; i ++) { for(int j = 0; j < n; j ++) { if(mpt[i][j] > 7) { printf("No\n"); ok = 0; break; } } } if(ok) printf("Yes\n"); } }
愚人节的礼物
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5069 Accepted Submission(s): 3091
Problem Description
四月一日快到了,Vayko想了个愚人的好办法——送礼物。嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物。盒子里面可以再放零个或者多个盒子。假设放礼物的盒子里不再放其他盒子。
用()表示一个盒子,B表示礼物,Vayko想让你帮她算出愚人指数,即最少需要拆多少个盒子才能拿到礼物。
用()表示一个盒子,B表示礼物,Vayko想让你帮她算出愚人指数,即最少需要拆多少个盒子才能拿到礼物。
Input
本题目包含多组测试,请处理到文件结束。
每组测试包含一个长度不大于1000,只包含'(',')'和'B'三种字符的字符串,代表Vayko设计的礼物透视图。
你可以假设,每个透视图画的都是合法的。
每组测试包含一个长度不大于1000,只包含'(',')'和'B'三种字符的字符串,代表Vayko设计的礼物透视图。
你可以假设,每个透视图画的都是合法的。
Output
对于每组测试,请在一行里面输出愚人指数。
Sample Input
((((B)()))()) (B)
Sample Output
4 1
Author
Kiki
最水的一道题,还是中文的,简单模拟。
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; char tt[1010]; int main() { while(~scanf("%s",tt)) { int len = strlen(tt); int cnt = 0; for(int i = 0; i < len; i ++) { if(tt[i] == '(') cnt ++; else if(tt[i] == ')') cnt --; else if(tt[i] == 'B') { printf("%d\n", cnt); break; } } } }
Consecutive sum
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1252 Accepted Submission(s): 577
Problem Description
Every body knew that 15 = 1+2+3+4+5 = 4+5+6 = 7+8. Now give you a number N, tell me how many ways to represent N as a sum of consecutive positive integers. For example, 15 have 3 ways to be found.
Input
Each line will contain an signed 32-bits integer N. Process to end of file.
Output
For each case, output the answer in one line.
Sample Input
15 1050
Sample Output
3 11
Author
Wiskey
一开始,我死在要怎么求一个数的因子的个数,我的思路是这样的,如果是奇素数,那就是只有对半加减一一种情况,然后其它的,求出因子个数,然后组合一下。找因子的时候,用小学求公约数的那种短除法(好像是这么叫的、),遍历求过来。
像这样:
总结: 题目都比较简单,但是自己太弱,就是这样、、
一开始,我死在要怎么求一个数的因子的个数,我的思路是这样的,如果是奇素数,那就是只有对半加减一一种情况,然后其它的,求出因子个数,然后组合一下。找因子的时候,用小学求公约数的那种短除法(好像是这么叫的、),遍历求过来。
像这样:
6 = 2^1 * 3^1 因子个数 = (1+1)*(1+1) = 4
24 = 2^3 * 3^1 因子个数 = (3+1)*(1+1) = 8
然后就是先求素数表,等等,后来发现数据是int 的,有点不太好搞啊!
后来查了题解,其实是一道数学题!!
设n可以表示成i个连续整数之和,首项为a,
则n=a+(a+1)+……(a+i-1)=i*a+(1+2+……+(i-1))=i*a+(i*(i-1)/2)-->a=(n-(i*(i-1)/2))/i
枚举i,使得a右边能整除,ans++
代码无!
然后就是先求素数表,等等,后来发现数据是int 的,有点不太好搞啊!
后来查了题解,其实是一道数学题!!
设n可以表示成i个连续整数之和,首项为a,
则n=a+(a+1)+……(a+i-1)=i*a+(1+2+……+(i-1))=i*a+(i*(i-1)/2)-->a=(n-(i*(i-1)/2))/i
枚举i,使得a右边能整除,ans++
代码无!
总结: 题目都比较简单,但是自己太弱,就是这样、、