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 ...
随机推荐
- 413. Reverse Integer【LintCode java】
Description Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-b ...
- CSP201612-2:工资计算
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...
- [C++基础] tips
1. 在g++ 中使支持C++11 https://askubuntu.com/questions/773283/how-do-i-use-c11-with-g This you can do by ...
- eBay推Winit海外仓 鼓励卖家拓展北美市场
[亿邦动力网讯]2月11日消息,日前,跨境电商平台eBay与外贸电商服务商万邑通(Winit)合作,针对平台卖家推出了Winit美国海外仓,鼓励卖家拓展北美市场. 亿邦动力网获悉,Winit美国海外仓 ...
- 软工1816 · Alpha冲刺(5/10)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 后端代码复审 福大各个食堂的菜品口味量化.属性标记 组织前后端线下协作 接下来 ...
- java下执行mongodb
1.1连单台mongodb Mongo mg = newMongo();//默认连本机127.0.0.1 端口为27017 Mongo mg = newMongo(ip);//可以指定ip 端口默认 ...
- 【beta】Scrum站立会议第3次....11.6
小组名称:nice! 组长:李权 成员:于淼 刘芳芳韩媛媛 宫丽君 项目内容:约跑app(约吧) 时间:2016.11.6 12:00——12:30 地点:传媒西楼220室 本次对beta阶段的需 ...
- centOS7设置静态ip后无法上网的解决,【亲可测】
最近在VMware虚拟机里玩Centos,装好后发现上不了网.经过一番艰辛的折腾,终于找到出解决问题的方法了.最终的效果是无论是ping内网IP还是ping外网ip,都能正常ping通.方法四步走: ...
- android Eclipse there no select
点mainactivity类 右键 run as 进行 配置 就可运行
- CentOS 7 开放3306端口访问
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙.1.关闭firewall:systemctl stop firewalld.servicesystemctl ...