Number Steps
Total Submission(s): 2697 Accepted Submission(s): 1656

You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...5000.
3 4 2 6 6 3 4
6 12 No Number
——————————————————————————————————————————————————————————
主要是找规律。当x==y时 当x是偶数时,为x*2,如果是奇数时,为2*n-1,其他的数的话如果y < x,则为y==x时的数减去2就行了
/***********************
* 程序名:Number Steps.c
* 功能:ACM
************************/
#include <stdio.h>
int main()
{
int N, x, y;
scanf("%d", &N);
while(N--) {
scanf("%d %d", &x, &y);
if(x == y || x - y == 2) {
if(x == y) {
if(x % 2 == 0) {
printf("%d\n", x*2);
}
else {
printf("%d\n", x*2-1);
}
}
else {
if(x % 2 == 0) {
printf("%d\n", x*2-2);
}
else {
printf("%d\n", x*2-3);
}
}
}
else {
printf("No Number\n");
}
}
return 0;
}
1354



被折叠的 条评论
为什么被折叠?



