题意简述
将点按照要求放入平面直角坐标系中,求一个位置有没有点,若有,求这是第几个点。
题目分析
很显然,如果把这两行数连成两条直线,那么解析式分别为 $y=x$ 和 $y=x-2$ 那么不在这条直线上则一定没有数。
当点在要求的直线上时:
- 当 $y=x$ 时,若 $x$ 为偶数,则编号等于 $2x$,否则编号就是 $2x-1$。
- 当 $y=x-2$ 时,其实是对应 $y=x$ 的点向右平移2个单位。
判断输出即可。
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include<bits/stdc++.h> using namespace std; int T,x,y; int main(){ cin>>T; for(int i=1;i<=T;i++){ cin>>x>>y; if(x==y||y==x-2){ if(x==y){ if(x%2){ cout<<2*x<<endl; } else{ cout<<2*x-1<<endl; } } else{ if(x%2){ cout<<2*x+2<<endl; } else{ cout<<2*x+1<<endl; } } } else{ puts("No Number"); } } return 0; }
|