题意:第一行表示有n个数据,第二行有n个数字,第i个数表示第i个数据,每组数据表示在n*n的正方形的边上,从左下角顺时针方向走,步长为n+1,求出走几步能回到原点
链接:http://codeforces.com/problemset/problem/194/B
思路:规律题,判断n边长的奇偶性,当n为偶数时输出4*n+1,当n为奇数时,判断(n-1)/2的奇偶性,若(n-1)/2为奇数,输出n+1,若(n-1)/2为偶数,输出2*n+1
注意点:无
以下为AC代码:
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | ||
---|---|---|---|---|---|---|---|---|---|---|
9734340 | Practice: luminous11 | 194B - 21 | GNU C++11 | Accepted | 92 ms | 4 KB | 2015-02-06 10:03:49 | 2015-02-06 10:03:49 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
//Problem D
int main()
{
ios::sync_with_stdio( false );
ll n;
while ( cin >> n ){
ll num;
for ( ll i = 0; i < n; i ++ ){
cin >> num;
if ( num & 1 ){
ll tmp = num / 2;
if ( tmp & 1 ){
cout << num + 1 << endl;
}
else{
cout << 2 * num + 1 << endl;
}
}
else{
cout << 4 * num + 1 << endl;
}
}
}
return 0;
}