# [POI2004]GRA

Description

Input

Output

Sample Input
For the following input data1:
5 2
1 3
For the following input2 data:
5 2
2 3

Sample Output
1
0

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')    f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10)     print(x/10);
putchar(x%10+'0');
}
const int N=1e6;
int val[N+10],step[N+10];
int main(){
if (val[n]==m-1){
ans=1;
for (int i=n-1;i&&val[i+1]-val[i]==1;i--)	ans++;
printf("%d\n",ans);
return 0;
}
val[n+1]=m-1;
for (int i=n;i;i--)
if (val[i+1]-val[i]==1)	step[tot]++;
else	if (val[i+1]-val[i]==2)	step[++tot]=1;
else	if ((val[i+1]-val[i]-1)&1)	tot+=3,step[tot]=1;
else	tot+=2,step[tot]=1;
for (int i=1;i<=tot;i+=2)	tmp^=step[i];
if (tmp){
for (int i=1;i<=tot;i+=2)	if ((step[i]^tmp)<step[i])	ans++;
for (int i=2;i<=tot;i+=2)	if ((step[i-1]^tmp)>step[i-1]&&(step[i-1]^tmp)<=step[i-1]+step[i])	ans++;
printf("%d\n",ans);
}else	putchar('0');
return 0;
}

posted @ 2018-02-08 23:03  Wolfycz  阅读(360)  评论(0编辑  收藏  举报