codeforces 463A Caisa and Sugar 解题报告
题目链接:http://codeforces.com/problemset/problem/463/A
题目意思:某个人有 s dollar的钱,有 n 种类型的糖果,第 i 种糖果的价值为 xi dollar + yi cent。这个商场比较古怪,如果收了顾客的cent,它不会找回相应的cent,而是用对应的sweet来替代。这个人只可以买一种类型的糖果,前提是 s dollar 大于等于糖果的价值,问最多可以得到的sweet是多少。
有几个细节需要注意:
(1)如果够钱买,但是糖果的cent 为 0,这个人是得不到任何sweet!
(2)判断够不够钱买糖果的时候,不能只单纯看dollar,而要看埋对应的cent。例如这组数据:
1 10
10 10
这个人是买不起这种糖果的!
(3)sweet 数 = 100 - yi(前提是买得起)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ; struct node
{
int x, y;
bool operator < (const node& a) const
{
return x < a.x;
} }sugar[maxn]; int main()
{
int s, n;
while (scanf("%d%d", &n, &s) != EOF)
{
for (int i = ; i < n; i++)
scanf("%d%d", &sugar[i].x, &sugar[i].y);
sort(sugar, sugar+n);
int ans = ;
int flag = ;
for (int i = ; i < n; i++)
{
if (sugar[i].x > s)
break;
else if (sugar[i].x == s && sugar[i].y > ) // 对应情况2
continue;
else
{
if (sugar[i].y == ) // 对应第一种情况
ans = max(ans, );
else
ans = max(ans, -sugar[i].y);
flag = ;
}
}
printf("%d\n", flag ? ans : -);
}
return ;
}
codeforces 463A Caisa and Sugar 解题报告的更多相关文章
- codeforces 463B Caisa and Pylons 解题报告
题目链接:http://codeforces.com/problemset/problem/463/B 题目意思:Caisa 站在 0 pylon 并且只有 0 energy,他需要依次跳过1 pyl ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
- codeforces 462C Appleman and Toastman 解题报告
题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...
- codeforces 460A Vasya and Socks 解题报告
题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...
随机推荐
- (BruteForce)暴力破解经典题目总结
在算法竞赛中,很多问题是来不及用数学公式推导出来的.或者说根本就找不到数学规律,这时我们就需要使用枚举来暴力破解. 不过枚举也是需要脑子的,一味的暴力只能超时.因此我这里选择了几道mooc上经典的题目 ...
- 笔记-迎难而上之Java基础进阶4
内部类创建多线程 //匿名内部类创建多线程 public class InnerClassThread{ public static void main(String[] args){ //回忆一下之 ...
- ios- nil NULL 和 NSNull
因为objective-c的集合对象,比如nsarray, nsdictionary, nsset等,都有可能包含nsnull对象,所以,如果以下代码中的item为nsnull,则会引起程序崩溃. N ...
- Go -- 接口赋值
在go语言中,接口赋值分为2中情况: 1.将对象实例赋值给接口: 2.将一个接口赋值给另一个接口. 1.将对象实例赋值给接口: 要求对象实现了接口的所有方法. 2.将接口赋值给另一个接口: 假设接口A ...
- Celery 启动报错 can_read() got an unexpected keyword argument timeout
问题: Celery 启动报错 can_read() got an unexpected keyword argument timeout 方案:更改redis版本和celery版本,我使用下面的ce ...
- OpenGL - Tessellation Shader 【转】
http://blog.sina.com.cn/s/blog_8c7d49f20102v4qm.html Patch is just an ordered list of vertices (在tes ...
- netd ResponseCode
100 Requestion action was initiated; expect another reply before proceeding with a new command. 200 ...
- 转:Android IOS WebRTC 音视频开发总结 (系列文章集合)
随笔分类 - webrtc Android IOS WebRTC 音视频开发总结(七八)-- 为什么WebRTC端到端监控很关键? 摘要: 本文主要介绍WebRTC端到端监控(我们翻译和整理的,译 ...
- substr使用注意
substr使用时要判断起点和长度是否超过了串本身的长度,否则会抛异常
- 7.JAVA编程思想笔记隐藏实施过程
欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/51040237 "进行面向对象的设计时,一项主要的考虑是:怎样将发生变 ...