【題目】http://acm.hdu.edu.cn/showproblem.php?pid=4768php
【報告】app
題目中已經說了,保證最多出現一個奇數,因此能夠用異或的想法。把全部的數異或起來,若是最後結果是0,那麼說明沒有奇數,否則剩下那個數就是惟一奇數。(在此不做證實)大數據
比賽的時候一直很糾結,被大數據嚇到了,一直沒敢作,結果到4小時才A(坑爹啊!!否則就進長春現場賽了!!)spa
貌似是陳題吧。get
【程序】class
// Task: 4768 Flyer
#include
#include
#include
#include程序
#define N 20000
using namespace std;
int n,ans;
int a[N+1],b[N+1],c[N+1];
int main()
{
while (scanf("%d",&n)!=EOF)
{
ans=0;
for (int i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
for (int k=a[i];k<=b[i];k+=c[i])
ans=ans^k;
}
if (ans==0) printf("DC Qiang is unhappy.\n");
else
{
int s=0;
for (int i=1;i<=n;i++)
if (ans>=a[i]&&ans<=b[i]&&((ans-a[i])%c[i]==0))
s++;
printf("%d %d\n",ans,s);
}
}
return 0;
}
數據