洛谷 P1161 开灯 C/C++

  • a[i] = !a[i] 控制开关灯 异或^控制也行
//P1161 开灯
//#define LOCAL
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
#define clr(x) memset(x,0,sizeof((x)))
const int maxn = 2e6+1;
#define MAX(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c)))
#define _max(a,b) ((a) > (b) ? (a) : (b))
#define _min(a,b) ((a) < (b) ? (a) : (b))
#define _for(a,b,c) for(int a = b;a
int main() {
     
#ifdef LOCAL 
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	int n,t,buf[maxn],x;
	double a;
	clr(buf);
	cin>>n;
	_for(i,0,n) {
     
		cin>>a>>t;
		for(int j = 1;j<=t;j++) {
     
			x = a*j;
			buf[x] = !buf[x];
		}
	}
	for(int i = 0;;i++) {
     
		if(buf[i]){
     
			cout<<i;
			break;
		}
	}
	return 0;
}

你可能感兴趣的:(洛谷,c++,c语言,算法)