首页 > 代码库 > 校赛部分水题
校赛部分水题
1236: xq and Crystal Mine
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 313 Solved: 76
[Submit][Status][Web Board]
Description
xq once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n>1) is an n?*?n matrix with a diamond inscribed into it.
You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.
Input
The only line contains an integer n (3<=n<=101; n is odd).
Output
Output a crystal of size n.
Sample Input
3
5
7
Sample Output
*D*
DDD
*D*
**D**
*DDD*
DDDDD
*DDD*
**D**
***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***
HINT
Source
小Q
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char a[105][105]; int main() { int n; while(scanf("%d", &n)!=EOF) { for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { a[i][j] = '*'; } } for(int i=0; i<=n/2; i++) { for(int j=n/2-i; j<=n/2+i; j++) { a[i][j] = 'D'; } } for(int i=n/2; i<n; i++) { for(int j=n/2-(n-i-1); j<=n/2+(n-i-1); j++) { a[i][j] = 'D'; } } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { printf("%c", a[i][j]); } printf("\n"); } } return 0; }
1246: xq的难题
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 351 Solved: 119
[Submit][Status][Web Board]
Description
xq自从知道了高斯用一个公式求出1到100的正整数和,心里对高斯十分崇拜,因此,他就想出很多与与类似的问题,一来彰显自己对高斯的崇拜,二来表明自己是多么的聪明。每次xq想出的问题都可以被自己很快的解答出来,渐渐的,xq心有余而力不足了,刚开始的问题都是很简单的,不用思考就能得出答案,到后来,得想好长时间才能做出正确的解答。现在xq遇到了对自己来说最大的难题,这道题目xq已经想了3天3夜,还没有给出正确解答。在xq打算放弃解答的时候,xq遇到了会计算机的你,xq听说计算机的计算速度十分快,xq就打算再试最后一次,当然,他是求你帮他解决这个困难的问题。xq的问题与高斯的问题很像,不同的是,xq想知道的是从1到n(包括1和n)中间的所有偶数的和是多少。
Input
测试数据有多组,你需要处理到文件结尾(EOF)。
每组数据包括一个正整数n(1<=n<=100)。测试数据之间用换行符分隔。
Output
每组测试数据输出从1到n的所有偶数的和。
Sample Input
1
3
Sample Output
0
2
HINT
Source
小Q
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { int n; while(scanf("%d", &n)!=EOF) { int ans = 0; for(int i=1; i<=n; i++) { if(i%2==0)ans+=i; } printf("%d\n", ans); } return 0; }
1240: Text Holes
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 281 Solved: 94
[Submit][Status][Web Board]
Description
xq wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example letters "A", "D", "O", "P", "Q" "R",divide the plane into two regions so we say these letters each have one hole. Similarly, letter "B" has two holes and letters such as "C", "E", "F", "K" have no holes. We say that the number of holes in the text is equal to the total number of holes in the letters of the text. Help Chef to determine how many holes are in the text.
Input
The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input.
Output
For each test case, output a single line containing the number of holes in the corresponding text.
Sample Input
2
CODECHEF
DRINKEATCODE
Sample Output
2
5
HINT
Source
小Q
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char a[110]; int judge(char a) { if(a == 'A')return 1; else if(a == 'D') return 1; else if(a == 'O') return 1; else if(a == 'P') return 1; else if(a == 'Q') return 1; else if(a == 'R') return 1; else if(a == 'B') return 2; else return 0; } int main() { int T; scanf("%d", &T); while(T--) { scanf("%s", a); int ans = 0, len = strlen(a); for(int i=0; i<len; i++) { ans +=judge(a[i]); } printf("%d\n", ans); } return 0; }
1241: 斐波那契数
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 590 Solved: 68
[Submit][Status][Web Board]
Description
xq最近迷恋上了斐波那契数列,因为当n趋向于无穷大时,后一项与前一项的比值越来越逼近黄金分割0.618。不过令xq不开心的是,斐波那契数的增长速度太快了,以至于当n很大时,用计算机中的32位整数甚至64位整数都已经不能表示这个数了。基于这个原因,xq遇到了这个难题,xq想要知道第K(0<=K<=10^10000)项斐波那契数是奇数还是偶数,因为K太大了,xq不知道怎么解决这个问题,现在xq想让你解决这个问题。斐波那契数列是如下的一个数列,0,1,1,2,3,5……,其通项公式为F(n)=F(n-1)+F(n-2),(n>=2) ,其中F(0)=0,F(1)=1。
Input
第一行,T,表示有1<=T<100个测试样例。
接下来T行,每行一个数据K(0<=K<=10^10000),表示要判定的是哪一项。
Output
如果第K项是偶数,输出YES,否则输出NO。
Sample Input
2
0
1
Sample Output
YES
NO
HINT
Source
小Q
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char a[10005]; int main() { int T; scanf("%d", &T); while(T--) { scanf("%s", a); int m = 0, len = strlen(a); for(int i=0; i<len; i++) { m += a[i]-'0'; } if(m%3==0)printf("YES\n"); else printf("NO\n"); } return 0; }
1242: 唐学长的蜜月之旅 续集
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 288 Solved: 15
[Submit][Status][Web Board]
Description
今年十月一日,唐学长又和他的女朋友出去旅游了! 这一次唐学长带着他的女朋友来到了北国江南—信阳这个美丽的城市。
陪着女朋友走在步行街购物的唐学长惊讶地发现初中的数学老师小强现在改行开起了小吃店。作为唐学长曾经的数学老师,小强想要了解唐学长现在的数学水平,于是他给唐学长出了一道数论难题,并对唐学长说“如果你能把这道题做出来,今晚我请客!”。
现在已知两个数gcd和lcm,问唐学长是否存在两个数a,b(a<=b)使得恰好它们的最大公约数为gcd,而最小公倍数为lcm。
Input
输入包含多组样例!每组样例先输入整数T(T<120),接下来有T行,每行有两个数gcd 和 lcm(1<=gcd<=lcm<2^31)
Output
对应每行输入,如果不存在a b满足条件,输出:“senior Tang is so smart!”,否则输出a b(a,b之间用空格隔开);如果存在多组解,输出对应a值最小的一组,详细输出格式见样例。
Sample Input
2
1 2
3 4
Sample Output
1 2
senior Tang is so smart!
HINT
假定你已经会了求GCD(最大公约数)的函数。
求LCM(最小公倍数)函数如下:
int lcm(int a, int b) {
return a/gcd(a,b)*b;
}
未完待续。。。
Source
殷华
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { int gcd, lcm, T; while(scanf("%d", &T)!=EOF) { while(T--) { scanf("%d %d", &gcd, &lcm); if(gcd<=lcm && lcm%gcd==0) printf("%d %d\n", gcd, lcm); else printf("senior Tang is so smart!\n"); } } return 0; }
链接:正式赛 热身赛
校赛部分水题