codeforces A. Group of Students 解题报告
题目链接:http://codeforces.com/problemset/problem/357/A
题目意思:将一堆人分成两组:beginners 和 intermediate coders 。每一个人都有一个point,给出每一个point里的总人数(Ci 个人有分数 i )和 x,y,需要找出划分为两组后,每一个组的人数(假设为a,b)符合 x <= a <= y 并且 x<= b <= y 的条件,输出这a个人是小于哪个point的,这个point还应该满足另一组的b个人都不小于它。当不能找到这个point符合条件时,输出0.
直接模拟即可。不断累加读入的人数,当这个人数 >= x时,就验证(总人数 - 这个从前往后依次累加的人数)是否也满足 <= y这个条件,一旦发现满足,就得到答案了,此时输出对应累加的人数中最后一个人所拥有的point。这里用到结构体来处理。
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std; const int maxn = 1e4 + ; struct students
{
int num; // 每一个分数所对应的人数
int point;
} exa[maxn]; int main()
{
int x, y, m, i, flag, sum1, sum2, sum;
while (scanf("%d", &m) != EOF)
{
sum = ;
for (i = ; i <= m; i++)
{
scanf("%d", &exa[i].num);
sum += exa[i].num;
exa[i].point = i;
}
scanf("%d%d", &x, &y);
sum1 = ;
flag = ;
for (i = ; i <= m; i++)
{
sum1 += exa[i].num; // 划分后第一个组的人数
sum2 = sum - sum1; // 划分后第二个组的人数
if ((sum1 >= x && sum1 <= y) && (sum2 >= x && sum2 <= y))
{
flag = ; // 找到一个解的标志
break;
}
}
if (flag)
printf("%d\n", exa[i+].point);
else
printf("0\n");
}
return ;
}
codeforces A. Group of Students 解题报告的更多相关文章
- 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 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- 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 的倍 ...
随机推荐
- 【SDOI2009】解题汇总
又开了波专题,感觉就和炉石开冒险一样...(说的好像我有金币开冒险似的) /---------------------------------------------/ BZOJ-1226 [SDOI ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- window自动切换ip的脚本
因为总要切换ip,所以百度了一下脚本 如下http://jingyan.baidu.com/article/d2b1d1029d21b95c7e37d4fa.html 动态ip netsh inter ...
- 使用servletAPI三种方式简单示例
一.直接实现Action接口或集成ActionSupport类(推荐) public class HelloAction implements Action { @Override public St ...
- 利用a标签自动解析URL
parseURL // This function creates a new anchor element and uses location // properties (inherent) to ...
- swift项目中引入OC框架
- golang社工库数据扫描程序
https://github.com/xiaojiong/scanfile 演示站点: http://www.weigongkai.com/ 7G数据 2s完成扫描 package scanfil ...
- XSS 自动化检测 Fiddler Watcher & x5s & ccXSScan 初识
一.标题:XSS 自动化检测 Fiddler Watcher & x5s & ccXSScan 初识 automated XSS testing assistant 二.引言 ...
- DedeCMS全版本通杀SQL注入漏洞利用代码
EXP: Exp:plus/recommend.php?action=&aid=1&_FILES[type][tmp_name]=\' or mid=@`\'` /*!50000u ...
- web后门排查与高效分析web日志技巧
今年一直大大小小的事情忙,很少有时间能静下心写个文章,所以最近博客更新也越来越少了,公司现在安全团队在我这边,一直在玩命的招人.下个月8号有一个互联网金融的会,4月在qcon北京站,都以嘉宾的身份去分 ...