codeforce B

cf B题,莫名其妙过,g++显示输入输出%lld有问题,,,明天改吧

原题(http://codeforces.com/gym/227252/standings/friends/true

By ronnie14165, contest: XDU_ACM_SUMMER ROUND 5 (Based on Educational Codeforces Round 49), problem: (B) Numbers on the Chessboard, Accepted, #
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

long long n;
int T;
long long ans;
long long a, b;

long long fun ( )
{
    if(n%2==0)
    {
        if(a%2==0&&b%2==0)  ans = n/2*(a-1)+b/2;
        if(a%2==1&&b%2==1)  ans = n/2*(a-1)+(b+1)/2;
        if(a%2==1&&b%2==0)  ans = n/2*(a-1)+b/2+n*n/2;
        if(a%2==0&&b%2==1)  ans = n/2*(a-1)+(b+1)/2+n*n/2;
    }
    if(n%2==1)
    {
        if(a%2==0&&b%2==0)  ans = n*(a-2)/2+b/2+(n+1)/2;
        if(a%2==1&&b%2==1)  ans = n*(a-1)/2+(b+1)/2;
        if(a%2==1&&b%2==0)  ans = n*(a-1)/2+b/2+n*n/2+1;
        if(a%2==0&&b%2==1)  ans = n*(a-2)/2+(b+1)/2+n*n/2+1+(n-1)/2;
    }
    return ans;
}
int main()
{

    cin >> n >> T;
    while(T--)
    {
        //scanf("%l64d%l64d",&a,&b);
        scanf("%lld%lld",&a,&b);
        long long temp = fun();
        printf("%lld\n",temp);
    }
    
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/ronnielee/p/9503402.html