Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类
1 second
256 megabytes
standard input
standard output
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
5
3 4 3 2 1
6 8
3
5
0 3 3 4 2
3 10
4
2
2 5
3 6
0
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int m;
int a[];
int main()
{
scanf("%d",&m);
int he=;
for(int i=;i<=m;i++)
{
scanf("%d",&a[i]);
he+=a[i];
}
int x,y;
int sum=;
int ans=;
scanf("%d %d",&x,&y);
for(int i=;i<=m;i++)
{
sum+=a[i];
if(sum>y)
{ printf("0\n");
return ;
}
if((sum>=x&&sum<=y)&&(he-sum>=x&&he-sum<=y))
{
printf("%d\n",i+);
return ;
}
}
printf("0\n");
return ;
}
1 second
256 megabytes
standard input
standard output
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be m dances;
- exactly three people must take part in each dance;
- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has n dancers, and their number can be less than 3m. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the m dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the n dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
The first line contains two space-separated integers n (3 ≤ n ≤ 105) and m (1 ≤ m ≤ 105) — the number of dancers and the number of dances, correspondingly. Then m lines follow, describing the dances in the order of dancing them. The i-th line contains three distinct integers — the numbers of the dancers that take part in the i-th dance. The dancers are numbered from 1 to n. Each dancer takes part in at least one dance.
Print n space-separated integers: the i-th number must represent the color of the i-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
7 3
1 2 3
1 4 5
4 6 7
1 2 3 3 2 2 1
9 3
3 6 9
2 5 8
1 4 7
1 1 1 2 2 2 3 3 3
5 2
4 1 5
3 1 2
2 3 1 1 3 题意:n个舞者 m个舞 每个舞蹈由3个不同的舞者组成 并且每个舞者的衣着颜色不同 问你n个舞者的衣着分别为什么 (1,2,3代表三种颜色)
题解:具体看代码 大致思想就是 固定第i位置的舞者的衣着为i 通过交换位置 向上对齐
#include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m;
int re[];
int a[][];
int mp[][];
int aa,bb,cc;
int main()
{
scanf("%d %d",&n,&m);
memset(mp,,sizeof(mp));
scanf("%d %d %d",&aa,&bb,&cc);
mp[aa][]=;
mp[bb][]=;
mp[cc][]=;
a[][]=aa;a[][]=bb;a[][]=cc;
for(int i=;i<=m;i++){
scanf("%d %d %d",&aa,&bb,&cc);
a[i][]=aa;a[i][]=bb;a[i][]=cc;
for(int j=;j<=;j++){
if(mp[aa][j]==){
if(j!=){
swap(a[i][],a[i][j]);
}
}
if(mp[bb][j]==){
if(j!=){
swap(a[i][],a[i][j]);
}
}
if(mp[cc][j]==){
if(j!=){
swap(a[i][],a[i][j]);
}
}
}
mp[a[i][]][]=;
mp[a[i][]][]=;
mp[a[i][]][]=;
}
for(int j=;j<=;j++)
{
for(int i=;i<=n;i++)
{
re[a[i][j]]=j;
}
}
for(int i=;i<=n;i++)
printf("%d ",re[i]);
printf("\n");
return ;
}
3 seconds
256 megabytes
standard input
standard output
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:
- There are n knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to n.
- The tournament consisted of m fights, in the i-th fight the knights that were still in the game with numbers at least li and at most ri have fought for the right to continue taking part in the tournament.
- After the i-th fight among all participants of the fight only one knight won — the knight number xi, he continued participating in the tournament. Other knights left the tournament.
- The winner of the last (the m-th) fight (the knight number xm) became the winner of the tournament.
You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number b was conquered by the knight number a, if there was a fight with both of these knights present and the winner was the knight number a.
Write the code that calculates for each knight, the name of the knight that beat him.
The first line contains two integers n, m (2 ≤ n ≤ 3·105; 1 ≤ m ≤ 3·105) — the number of knights and the number of fights. Each of the following m lines contains three integers li, ri, xi (1 ≤ li < ri ≤ n; li ≤ xi ≤ ri) — the description of the i-th fight.
It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.
Print n integers. If the i-th knight lost, then the i-th number should equal the number of the knight that beat the knight number i. If the i-th knight is the winner, then the i-th number must equal 0.
4 3
1 2 1
1 3 3
1 4 4
3 1 4 0
8 4
3 5 4
3 7 6
2 8 8
1 8 1
0 8 4 6 4 8 6 1
Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.
题意:n个人 m场比赛 x战胜了 [l,r]中除了已经被淘汰的和他本身的人 输出每个人是被谁战胜的
题解:set
#include<bits/stdc++.h>
#define ll __int64
//code by drizzle
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
set<int> s;
set<int>::iterator it,itt;
int n,m;
int a[];
int l,r,x;
int main()
{
scanf("%d %d",&n,&m);
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
s.insert(i);
for(int i=;i<=m;i++)
{
scanf("%d %d %d",&l,&r,&x);
it=s.lower_bound(l);
for(;(*it)<=r&&it!=s.end();it=itt){
a[*it]=x;
itt=it;
itt++;
s.erase(*it);
}
s.insert(x);
a[x]=;
}
for(int i=;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
return ;
}
/*
11 6
1 2 2
7 8 7
3 4 4
6 9 6
5 10 10
2 11 11
*/
1 second
256 megabytes
standard input
standard output
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip.
The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student.
However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number.
After all the swaps each compartment should either have no student left, or have a company of three or four students.
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
5
1 2 2 4 3
2
3
4 1 1
2
4
0 3 0 4
0
题意:给你n个数 数的范围为0~4 经过最少的操作(每次改变1) 使得n个数的目标状态为{0,3,4}
题解:恶心分类
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
map<int,int>mp;
int exm;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&exm);
mp[exm]++;
}
if(mp[]>=mp[])
{
int len=mp[]-mp[];
int jishu=mp[]+(len/)*;
mp[]=mp[]+len/+mp[];
len=len%;
if(len==)
printf("%d\n",jishu);
if(len==)
{
if(mp[]>=)
printf("%d\n",jishu+);
else if(mp[]>=)
printf("%d\n",jishu+);
else
printf("-1\n");
}
if(len==)
{
if(mp[]>=||mp[]>=)
printf("%d\n",jishu+);
else
printf("-1\n");
}
}
else
{
int len=mp[]-mp[];
int jishu=mp[]+(len/)*;
mp[]=mp[]+(len/)*+mp[];
len=len%;
if(len==)
printf("%d\n",jishu);
if(len==)
{
if(mp[]>=)
printf("%d\n",jishu+);
else if(mp[]>=)
printf("%d\n",jishu+);
else
printf("-1\n");
}
if(len==)
{
printf("%d\n",jishu+);
}
}
return ;
}
Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类的更多相关文章
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)
题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- Codeforces Round #207 (Div. 2) A. Group of Students
#include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...
- Codeforces Round #207 (Div. 1)B(数学)
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...
- Codeforces Round #207 (Div. 2)C
读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...
- Codeforces Round #207 (Div. 2)
A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int ...
- Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...
随机推荐
- java获取IP地址
最近在一个多系统集成的项目中,由于跳转路径含IP地址,每次IP改了重启项目都得改好多地方,甚是麻烦.刚在网上了解到java获取IP地址,给大家分享下: 首先要导入jar包 request.getRem ...
- mac安装pkg 一直“正在验证” 卡着
今天换了新mac, 但是之前wireshark(抓包工具) 不能用了 ,要安装Xquartz. 下载之后一直卡着, 网上找了半天没有解决方法. 最后我重启一下就好了... 重启一下. 2. 15款ma ...
- dede 后台登录以后一片空白
网上说的是 找到:include/common.inc.php文件,打开,查找程序代码: //error_reporting(E_ALL); error_reporting(E_ALL || ~E_ ...
- Python 数据图表工具的比较
Python 的科学栈相当成熟,各种应用场景都有相关的模块,包括机器学习和数据分析.数据可视化是发现数据和展示结果的重要一环,只不过过去以来,相对于 R 这样的工具,发展还是落后一些. 幸运的是,过去 ...
- ES6的新特性(9)——对象的扩展
对象的扩展 属性的简洁表示法 ES6 允许直接写入变量和函数,作为对象的属性和方法.这样的书写更加简洁. const foo = 'bar'; const baz = {foo}; baz // {f ...
- 网站UI分析
本次网站UI分析我选择的是我们石家庄铁道大学的网站,首先对于网站的分析建立在我经常使用鼠须的基础上,我可以很好的站在用户的角度来进行分析,否则对于你不熟悉的网站你可能是不能很好地体验到他的 结构. U ...
- 领悟JavaScript面向对象
JavaScript 是面向对象的.但是不少人对这一点理解得并不全面. 在 JavaScript 中,对象分为两种.一种可以称为“普通对象”,就是我们所普遍理解的那些:数字.日期.用户自定义的对象(如 ...
- jQuery之元素查找
在已经匹配出的元素集合中根据选择器查找孩子/父母/兄弟标签1. children(): 子标签中找2. find() : 后代标签中找3. parent() : 父标签4. prevAll() : 前 ...
- PAT 甲级 1144 The Missing Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160 Given N integers, you ...
- linux应用自启动配置
Linux在启动时,会自动执行/etc/rc.d目录下的初始化程序,因此我们可以把启动任务放到该目录下: 1.因为其中的rc.local是在完成所有初始化之后执行,因此可以把启动脚本写到里面: 2.用 ...