2395: 【入门】【P1161】开灯

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:30 解决:16

题目描述

在一条无限长的路上,有一排无限长的路灯,编号为 lns="http://www.w3.org/1998/Math/MathML">1,2,3,4,

每一盏灯只有两种可能的状态,开或者关。如果按一下某一盏灯的开关,那么这盏灯的状态将发生改变。如果原来是开,将变成关。如果原来是关,将变成开。

在刚开始的时候,所有的灯都是关的。小明每次可以进行如下的操作:

指定两个数,lns="http://www.w3.org/1998/Math/MathML">,lns="http://www.w3.org/1998/Math/MathML"> 为实数,lns="http://www.w3.org/1998/Math/MathML"> 为正整数)。将编号为 lns="http://www.w3.org/1998/Math/MathML">,2×,3×,,× 的灯的开关各按一次。其中 lns="http://www.w3.org/1998/Math/MathML"> 表示实数 lns="http://www.w3.org/1998/Math/MathML"> 的整数部分。

在小明进行了 lns="http://www.w3.org/1998/Math/MathML"> 次操作后,小明突然发现,这个时候只有一盏灯是开的,小明很想知道这盏灯的编号,可是这盏灯离小明太远了,小明看不清编号是多少。

幸好,小明还记得之前的 lns="http://www.w3.org/1998/Math/MathML"> 次操作。于是小明找到了你,你能帮他计算出这盏开着的灯的编号吗?

输入

第一行一个正整数 lns="http://www.w3.org/1998/Math/MathML">,表示 lns="http://www.w3.org/1998/Math/MathML"> 次操作。

接下来有 lns="http://www.w3.org/1998/Math/MathML"> 行,每行两个数,lns="http://www.w3.org/1998/Math/MathML">,。其中 lns="http://www.w3.org/1998/Math/MathML"> 是实数,小数点后一定有 lns="http://www.w3.org/1998/Math/MathML">6 位,lns="http://www.w3.org/1998/Math/MathML"> 是正整数。

输出

仅一个正整数,那盏开着的灯的编号。

样例输入 复制

3
1.618034 13
2.618034 7
1.000000 21

样例输出 复制

20

提示

记 lns="http://www.w3.org/1998/Math/MathML">==1=1+2+3++

对于 lns="http://www.w3.org/1998/Math/MathML">30% 的数据,满足 lns="http://www.w3.org/1998/Math/MathML">1000

对于 lns="http://www.w3.org/1998/Math/MathML">80% 的数据,满足 lns="http://www.w3.org/1998/Math/MathML">200000

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,满足 lns="http://www.w3.org/1998/Math/MathML">2000000

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,满足 lns="http://www.w3.org/1998/Math/MathML">5000,1<1000,1

数据保证,在经过 lns="http://www.w3.org/1998/Math/MathML"> 次操作后,有且只有一盏灯是开的,不必判错。而且对于所有的 lns="http://www.w3.org/1998/Math/MathML"> 来说,lns="http://www.w3.org/1998/Math/MathML">× 的最大值不超过 lns="http://www.w3.org/1998/Math/MathML">2000000


#include<iostream>
#include<cstring>
using namespace std;
int a[2000010];
int main(){
	int n,ans,t;
	double d;
	memset(a,-1,sizeof(a));
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>d>>t;
		for (int j=1;j<=t;j++){
			int k=(int)(d*j);  //或者 int k=int(d*j);
			a[k] *=-1;
		} 
	}
	for (int i=1;i<=2000000;i++) {
		if (a[i]==1) {
			ans=i;
			break;
		}
	}
	cout<<ans;
	return 0;
}