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 ...
随机推荐
- 451. Swap Nodes in Pairs【LintCode java】
Description Given a linked list, swap every two adjacent nodes and return its head. Example Given 1- ...
- 启动sshd时,报“Could not load host key”错
原文发表于cu:2016-05-24 现象:启动sshd服务时,虽看似服务启动成功,但客户端并不能连接上sshd服务器端.如下: [root@aefe8007a17d ~]# /usr/sbin/ss ...
- Apriori 获取关联规则实现
前言 自己的一个Apriori 获取关联规则的python实现.具体原理不讲,代码添加了说明,还是很好理解的. 数据预处理 #最小置信度 min_conf = 0.5 #最小支持度 min_sup = ...
- Paper Reading - Deep Captioning with Multimodal Recurrent Neural Networks ( m-RNN ) ( ICLR 2015 ) ★
Link of the Paper: https://arxiv.org/pdf/1412.6632.pdf Main Points: The authors propose a multimodal ...
- Python3 匿名函数
一 匿名函数 lambda函数也叫匿名函数,语法结构如下: lambda x:x+1 x --> 形参 x+1 --> 返回值,相当于return x+1 实例(Python3.0+): ...
- 复利计算器4.0之再遇JUnit
复利计算器4.0之再遇JUnit 前言 虽然之前的复利计算器版本已经尝试过使用JUnit单元测试,但由于没有系统性地学习过JUnit的使用,用得并不好,主要问题表现在测试的场景太少,并没有达到测 ...
- caffe神经网络模型的绘图
Python/draw_net.py, 这个文件,就是用来绘制网络模型的.也就是将网络模型由prototxt变成一张图片. 1.安装GraphViz # sudo apt-get install Gr ...
- 解释Spring中IOC, DI, AOP
oc就是控制翻转或是依赖注入.通俗的讲就是如果在什么地方需要一个对象,你自己不用去通过new 生成你需要的对象,而是通过spring的bean工厂为你长生这样一个对象.aop就是面向切面的编程.比如说 ...
- jdbc 6.0
1.获取数据库自动生成的键值 package com.rong.jielong; import java.sql.Connection; import java.sql.DriverManager; ...
- namesapce的作用 增加访问路径 目的:区分不同包的相同action的访问路径