B - Alcoholic( AtCoder Beginner Contest 189)

原题链接

思路

从头开始遍历比较与\(x\)的大小即可

注意浮点数判断大小的精度问题

AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
const LL mod=1e9+7;

double v[N],p[N];

int main()
{
	int n;
	double x;
	scanf("%d%lf",&n,&x);
	for(int i=0;i<n;i++) scanf("%lf%lf",&v[i],&p[i]);
	double now=0;
	for(int i=0;i<n;i++)
	{
		now+=v[i]*(p[i]/100.0);
		if(now-x>1e-9)
		{
			printf("%d\n",i+1);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}
posted @ 2021-08-11 13:58  TheWeak  阅读(34)  评论(0编辑  收藏  举报