CodeForces 194B Square

题意:第一行表示有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代码:

#AuthorProblemLangVerdictTimeMemorySentJudged  
9734340Practice:
luminous11
194B - 21GNU C++11Accepted92 ms4 KB2015-02-06 10:03:492015-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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值