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 的倍 ...
随机推荐
- 【CodeForces 312B】BUPT 2015 newbie practice #3A Archer
题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the targ ...
- BZOJ1045 [HAOI2008] 糖果传递
Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. Input 第一行一个正整数n<=987654321,表示小朋友的个数 ...
- 学习 easyui 之一:easyloader 分析与使用
http://www.cnblogs.com/haogj/archive/2013/04/22/3036685.html 使用脚本库总要加载一大堆的样式表和脚本文件,在 easyui 中,除了可以使用 ...
- Sublime的快捷键的使用
Default Keymap 1. Ctrl+L 选择整行(按住-继续选择下行) 2. Ctrl+Shift+K(shhift+del) 删除整行, ctrl + KK 从光标处删之行尾,Ctrl+K ...
- rockmongo用法
.简单查询 //xid=560870 and type=video { , "type": "video" } //查询数组中的数据 array( " ...
- Advice for applying Machine Learning
https://jmetzen.github.io/2015-01-29/ml_advice.html Advice for applying Machine Learning This post i ...
- VMWare提供了三种工作模式上网
VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式).要想在网络管理和维护中合理应用它们,你就应该先了解一下这三种工作模式. 1 ...
- pthread 学习系列 case2-- 使用互斥锁
ref http://www.ibm.com/developerworks/cn/linux/thread/posix_thread1/index.html #include <pthread. ...
- Linux 学习笔记(一)
Linux体系结构 下面是Linux体系结构的示意图: 在所有Linux版本中,都会涉及到以下几个重要概念: 内核:内核是操作系统的核心.内核直接与硬件交互,并处理大部分较低层的任务,如内存管理.进程 ...
- 菜鸟写的第一个chrome插件
一.新建一个文件夹,用来放插件的代码 二.首先新建配置文件manifest.json // 开发参考:http://open.chrome.360.cn/extension_dev/overview. ...