HDU - 4768 Flyer

题意:很好理解就不说了,用了异或,如果出现偶数次就会等于0,所以最后的数就是答案了,然后再根据num=A[i]+k*c[i],所以减去A[i]就是c[i]的倍数了,这就是sum++的判断条件,被杭电的输入,输出坑了很久

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 20010;

int n;
long long a[N], b[N], c[N];

int main(){
    while(~scanf("%d", &n)){
        long long num = 0;
        for(int i = 1; i <= n; i++){
            cin>>a[i]>>b[i]>>c[i];
            for(long long j = a[i]; j <= b[i]; j+=c[i]){
                num ^= j;
            }
        }
        long long sum = 0;
        for(int i = 1; i <= n; i++){
            if((num-a[i])%c[i]==0 && (num>=a[i])&&(num<=b[i]))
                sum++;
        }
        if(num==0){
            puts("DC Qiang is unhappy.");
            continue;
        }
        cout << num << " " << sum << endl;
    }
    return 0;
}



你可能感兴趣的:(HDU - 4768 Flyer)