Codeforces Round #388 (Div. 2) A,B,C,D
1 second
256 megabytes
standard input
standard output
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.
The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).
The first line of the output contains a single integer k — maximum possible number of primes in representation.
The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.
5
2
2 3
6
3
2 2 2
题意:给你一个数n,求n最多由多少个素数和相加;
思路:去最小的2,3即可;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9;
const ll INF=1e18+;
int main()
{
int n;
scanf("%d",&n);
if(n%)
{
printf("%d\n",(n-)/+);
printf("3 ");
for(int i=;i<(n-)/;i++)
printf("2 ");
}
else
{
printf("%d\n",n/);
for(int i=;i<n/;i++)
printf("2 ");
}
return ;
}
1 second
256 megabytes
standard input
standard output
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.
Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.
The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.
First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.
Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.
0 0
1 0
0 1
3
1 -1
-1 1
1 1
If you need clarification of what parallelogram is, please check Wikipedia page:
https://en.wikipedia.org/wiki/Parallelogram
题意:给你一个平行四边行的三个点求第四个点的可能位置;
思路:模拟;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9;
const ll INF=1e18+;
int x[],y[];
set<pair<int,int> >s;
set<pair<int,int> >::iterator it;
void getans(int pos,int dx,int dy)
{
s.insert(make_pair(x[pos]+dx,y[pos]+dy));
s.insert(make_pair(x[pos]-dx,y[pos]-dy));
}
int main()
{
int n;
for(int i=;i<=;i++)
{
scanf("%d%d",&x[i],&y[i]);
}
getans(,x[]-x[],y[]-y[]);
getans(,x[]-x[],y[]-y[]);
getans(,x[]-x[],y[]-y[]);
printf("%d\n",s.size());
for(it=s.begin();it!=s.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
return ;
}
1 second
256 megabytes
standard input
standard output
There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:
- Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employeen. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).
- When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.
- When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing withn who are still eligible to vote make their statements.
- The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
5
DDRRR
D
6
DDRRRR
R
Consider one of the voting scenarios for the first sample:
- Employee 1 denies employee 5 to vote.
- Employee 2 denies employee 3 to vote.
- Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
- Employee 4 denies employee 2 to vote.
- Employee 5 has no right to vote and skips his turn (he was denied by employee 1).
- Employee 1 denies employee 4.
- Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.
题意:n个人,分成两个党派,从1-n,每个人有投票的权利,从1-n按顺序开始投票
如果被人投了票,那么就没有投票的权利了; 也可以选择不投票
问最后一个有投票权利的党派是那个;
思路:贪心,对于一个人,需要投他后面离他最近的不同党派的人,因为前面的已经决定了,要让后面的人没有投票的人失去权利,并且离他近的更优;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
const ll INF=1e18+;
char a[N];
char b[N];
queue<char>q;
int check(int si,char c)
{
for(int i=;i<=si;i++)
if(a[i]!=c)
return ;
return ;
}
int main()
{
int n;
scanf("%d",&n);
scanf("%s",a+);
int si=n;
while()
{
if(check(si,'D'))break;
if(check(si,'R'))break;
int p=;
for(int i=;i<=si;i++)
{
if(q.empty())
q.push(a[i]);
else if(q.front()==a[i])
q.push(a[i]);
else
{
b[++p]=q.front();
q.pop();
}
}
int k=;
while(!q.empty())
{
a[++k]=q.front();
q.pop();
}
for(int i=;i<=p;i++)
a[++k]=b[i];
si=k;
}
printf("%c\n",a[]);
return ;
}
2 seconds
256 megabytes
standard input
standard output
There are n people taking part in auction today. The rules of auction are classical. There were n bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all.
Each bid is define by two integers (ai, bi), where ai is the index of the person, who made this bid and bi is its size. Bids are given in chronological order, meaning bi < bi + 1 for all i < n. Moreover, participant never makes two bids in a row (no one updates his own bid), i.e. ai ≠ ai + 1 for all i < n.
Now you are curious with the following question: who (and which bid) will win the auction if some participants were absent? Consider that if someone was absent, all his bids are just removed and no new bids are added.
Note, that if during this imaginary exclusion of some participants it happens that some of the remaining participants makes a bid twice (or more times) in a row, only first of these bids is counted. For better understanding take a look at the samples.
You have several questions in your mind, compute the answer for each of them.
The first line of the input contains an integer n (1 ≤ n ≤ 200 000) — the number of participants and bids.
Each of the following n lines contains two integers ai and bi (1 ≤ ai ≤ n, 1 ≤ bi ≤ 109, bi < bi + 1) — the number of participant who made the i-th bid and the size of this bid.
Next line contains an integer q (1 ≤ q ≤ 200 000) — the number of question you have in mind.
Each of next q lines contains an integer k (1 ≤ k ≤ n), followed by k integers lj (1 ≤ lj ≤ n) — the number of people who are not coming in this question and their indices. It is guarenteed that lj values are different for a single question.
It's guaranteed that the sum of k over all question won't exceed 200 000.
For each question print two integer — the index of the winner and the size of the winning bid. If there is no winner (there are no remaining bids at all), print two zeroes.
6
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
3
1 3
2 2 3
2 1 2
2 100000
1 10
3 1000
3
1 10
2 100
1 1000
2
2 1 2
2 2 3
0 0
1 10
Consider the first sample:
- In the first question participant number 3 is absent so the sequence of bids looks as follows:
- 1 10
- 2 100
- 1 10 000
- 2 100 000
Participant number 2 wins with the bid 100 000.
- In the second question participants 2 and 3 are absent, so the sequence of bids looks:
- 1 10
- 1 10 000
The winner is, of course, participant number 1 but the winning bid is 10 instead of 10 000 as no one will ever increase his own bid (in this problem).
- In the third question participants 1 and 2 are absent and the sequence is:
- 3 1 000
- 3 1 000 000
The winner is participant 3 with the bid 1 000.
题意:拍卖一个东西,n个操作,表示第i个人出价,并且出价递增,
q个询问,每个询问去掉k个人,即把这k个人的相关出价全部去掉;
求能拍卖下这个东西的人是那个,并且出价多少;
没有输出0 0;
思路:线段树+二分;
开始觉得一个人出价多次,怎么写,都不行;
但是后来你会发现,一个人的出价只是最大值有用;
k个人只要把最大值改成0即可;
你留下最大值就可以知道是必然是那个人拍下的东西;
把拍下东西的人的值改成0;
二分拍东西人的出价,>=其他人的出价最小值即可;
详见代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
const ll INF=1e18+;
int maxx[N<<];
vector<int>v[N];
void build(int l,int r,int pos)
{
if(l==r)
{
maxx[pos]=;
return;
}
int mid=(l+r)>>;
build(l,mid,pos<<);
build(mid+,r,pos<<|);
maxx[pos]=max(maxx[pos<<],maxx[pos<<|]);
}
void update(int p,int c,int l,int r,int pos)
{
if(l==r&&l==p)
{
maxx[pos]=c;
return;
}
int mid=(l+r)>>;
if(p<=mid)
update(p,c,l,mid,pos<<);
else
update(p,c,mid+,r,pos<<|);
maxx[pos]=max(maxx[pos<<],maxx[pos<<|]);
}
int query(int m,int l,int r,int pos)
{
if(l==r)
{
return l;
}
int mid=(l+r)>>;
if(maxx[pos<<]==m)
query(m,l,mid,pos<<);
else
query(m,mid+,r,pos<<|);
}
int a[N];
int main()
{
int n;
scanf("%d",&n);
build(,n,);
for(int i=; i<=n; i++)
{
int a,b;
scanf("%d%d",&a,&b);
v[a].push_back(b);
update(a,b,,n,);
}
int q;
scanf("%d",&q);
while(q--)
{
int k;
scanf("%d",&k);
for(int i=;i<=k;i++)
{
scanf("%d",&a[i]);
update(a[i],,,n,);
}
if(maxx[]==)
{
printf("0 0\n");
for(int i=;i<=k;i++)
{
int l=v[a[i]].size()-;
if(l<)
continue;
update(a[i],v[a[i]][l],,n,);
}
continue;
}
int pos=query(maxx[],,n,);
update(pos,,,n,);
int st=;
int en=v[pos].size()-,ans;
while(st<=en)
{
int mid=(st+en)>>;
if(v[pos][mid]>=maxx[])
{
ans=v[pos][mid];
en=mid-;
}
else
st=mid+;
}
printf("%d %d\n",pos,ans);
int l=v[pos].size()-;
update(pos,v[pos][l],,n,);
for(int i=;i<=k;i++)
{
int l=v[a[i]].size()-;
if(l<)continue;
update(a[i],v[a[i]][l],,n,);
}
}
return ;
}
Codeforces Round #388 (Div. 2) A,B,C,D的更多相关文章
- Codeforces Round #388 (Div. 2)
# Name A Bachgold Problem standard input/output 1 s, 256 MB x6036 B Parallelogram is Back s ...
- Codeforces Round #388 (Div. 2) - C
题目链接:http://codeforces.com/contest/749/problem/C 题意:给定一个长度为n的D/R序列,代表每个人的派别,然后进行发表意见,顺序是从1到n.每个人到他的回 ...
- Codeforces Round #388 (Div. 2) - B
题目链接:http://codeforces.com/contest/749/problem/B 题意:给定平行四边形的3个点,输出所有可能的第四个点. 思路:枚举任意两个点形成的直线,然后利用这两个 ...
- Codeforces Round #388 (Div. 2) - A
题目链接:http://codeforces.com/contest/749/problem/A 题意:给定一个数n,求把n分解成尽量多的素数相加.输入素数个数和具体方案. 思路:因为要尽量多的素数, ...
- Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)
题目大意 给定一个1到n的排列,然后随机选取一个区间,让这个区间内的数随机改变顺序,问这样的一次操作后,该排列的逆序数的期望是多少 首先,一个随机的长度为len的排列的逆序数是(len)*(len-1 ...
- Codeforces Round #388 (Div. 2) D
There are n people taking part in auction today. The rules of auction are classical. There were n bi ...
- Codeforces Round #388 (Div. 2) A+B+C!
A. Bachgold Problem 任何一个数都可以由1和2组成,由于n是大于等于2的,也就是可以由2和3组成.要求最多的素数即素数越小越好,很明显2越多越好,如果n为奇数则再输出一个3即可. i ...
- Codeforces Round #388 (Div. 2) C. Voting
题意:有n个人,每个人要么是属于D派要么就是R派的.从编号1开始按顺序,每个人都有一次机会可以剔除其他任何一个人(被剔除的人就不在序列中也就失去了剔除其他人的机会了):当轮完一遍后就再次从头从仅存的人 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- APP开发:一个APP开发需要哪些技术人员?
亿合科技小编了解到:国民老公王思聪曾经在一个访谈中谈到过,如果他是一个普通人,他会选择移动互联网去创业,因为做个网站或者App开发门槛较低,做大做强的机会也比较多.小编觉得创业就是投资,重 ...
- VR原理讲解及开发入门
本文是作者obuil根据多年心得专门为想要入门的VR开发者所写,由52VR网站提供支持. 1. VR沉浸感和交互作用产生的原理: 在之前,我们观看一个虚拟的创造内容是通过平面显示器的,52VR ...
- Leetcode: Longest Substring with At Most K Distinct Characters && Summary: Window做法两种思路总结
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- Java 线程的转换及状态
线程的状态转换是线程控制的基础. 线程状态总的可分为五大状态:分别是生.死.可运行.运行.等待/阻塞.用一个图来描述如下: 1.新建状态(New):新创建了一个线程对象. 2.就绪状态(Runnabl ...
- 今天携程出事了:让我们来学习下http的响应码
就在今天,2015年5月28日,中国最大的旅游机票预订网站--携程网粗大事了.据传携程网的数据库被人物理删除了,而容灾备份的数据又无法正常使用,服务器全面遭受瘫痪.每小时给携程带来的损失约100万美元 ...
- java运行环境和运行机制
先来介绍三个概念: JVM----JAVA virtual machine java虚拟机:对字节码提供相同的接口,对操作系统提供不同的接口,以适应各个OS JRE----JAVA runt ...
- 盒子模型(W3C盒子模型、IE盒子模型)
盒子模型:一个物体在页面中所占据的位置 盒子模型包含以下几种元素: padding:margin:content:border 这是大家都知道的,也是书本上定义说明的,但是在ie的情况下是有点区别的; ...
- iOS的数据持久化
所谓的持久化,就是将数据保存到硬盘中,使得在应用程序或机器重启后可以继续访问之前保存的数据.在iOS开发中,有很多数据持久化的方案,接下来我将尝试着介绍一下5种方案: plist文件(属性列表) pr ...
- 解决Window Azure: Failed to start Development Storage: the SQL Server instance ‘localhost\SQLExpress’ could not be found.
运行Window Arzure 项目,报如下错误: Windows Azure Tools: Failed to initialize Windows Azure storage emulator. ...
- FilterControl 显示时间并精确到时分秒的方法