Codeforces Round #524 (Div. 2) Margarite and the best present CodeForces - 1080B

找一下规律即可。。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
const int maxn =1e9+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;

int main()
{
	int q;scanf("%d",&q);
	while(q--)
	{
		int x,y;scanf("%d%d",&x,&y);
		if(x&1)
		{
			if(y&1) printf("%d\n",-y+(y-x)/2);
			else printf("%d\n",(y-x)/2+1);
		}
		else
		{
			if(y&1) printf("%d\n",-((y-x)/2+1));
			else printf("%d\n",y-(y-x)/2);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/wzazzy/article/details/84844491
今日推荐