谨以此篇记录我的一个思维缺陷

这篇博客记录了一道编程竞赛题目,Takahashi有若干种含有不同酒精百分比的饮料,当他的酒精摄入量超过特定阈值时会醉酒。程序的目标是找出导致他醉酒的饮料编号。博客作者通过一个简单的C++程序来解决这个问题,并反思了自己在思维上的一个小缺陷——缺乏逆向思考。
摘要由CSDN通过智能技术生成

谨以此篇记录我的一个思维缺陷

Problem Statement

Takahashi had N glasses of liquor.The amount and alcohol percentage of the i-th liquor were Vi milliliters and Pi percent by volume, respectively.
Takahashi gets drunk when his alcohol intake exceeds X milliliters.
Which of the N liquors was he drinking when he gets drunk? If he was not drunk even after drinking allthe liquors, print -1 instead.

Constraints

All values in input are integers.
1≤N≤10^3
0≤X≤10^6
1≤Vi≤10^3
0≤Pi≤100

Input

Input is given from Standard Input in the following format:
在这里插入图片描述

Output

If Takahashi got drunk when drinking the i-th liquor, print i. If he was not drunk even after drinking all the liquors, print -1 instead.

Sample Input 1 
2 15
200 5
350 3
 
Sample Output 1 
2

Sample Input 2 
2 10
200 5
350 3

Sample Output 2 
2

Sample Input 3 
3 1000000
1000 100
1000 100
1000 100

Sample Output 3 
-1
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n,x;
	int sum=0;
	cin>>n>>x;
	x*=100;//此篇意义所在之处
	int v[1005];
	for(int i=0;i<n;i++){
		int z,y;
		cin>>z>>y;
		v[i]=z*y;
	}
	for(int k=0;k<n;k++){
		sum+=v[k];
		if(sum>x) {
			cout<<k+1;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
} 

总结

此题思路很简单,而记录此篇的意义在于,我一个逆向思维的缺乏。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值