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 ...
随机推荐
- 导入csv文件到mysql
原文 给自己做备份的,高手们请忽略. 数据太大,用数据库客户端软件直接导入非常卡,还是直接执行SQL吧. 1.指定文件路径. 2.字段之间以逗号分隔,数据行之间以\r\n分隔(我这里文件是以\n分隔的 ...
- 为什么要配置sdk-tools/platform-toools?
为了方便使用Android SDK包含的开发工具,我们在系统环境变量中的Path设置Android SDK的安装目录下的tools目录. Android SDK中: platform-tools里有a ...
- PHP 返回JSON
有个朋友说PHP不能返回JSON对象,作为.net的我认为应该是可以的,设置一下header 就行了. 果不然,google 一下,备忘如下: <?php $result = array('Na ...
- paper 123: SVM如何避免过拟合
过拟合(Overfitting)表现为在训练数据上模型的预测很准,在未知数据上预测很差.过拟合主要是因为训练数据中的异常点,这些点严重偏离正常位置.我们知道,决定SVM最优分类超平面的恰恰是那些占少数 ...
- simvision使用
Access Design Source Code: 1)通过file---open来打开, 2)通过send to source viewer来看, 双击信号,进行driver的trace,显示在左 ...
- 【unity3d游戏开发脚本笔记之一:坐标系选择对物体运动的影响】
时间:2016年9月24日17:38:21 作者:yexiaopeng 博客园 在unity3d的世界中,其坐标系可分为四种,世界坐标系-WorldSpace 本地坐标系-LocalS ...
- Fiddler 常用文档
时间飞逝,已经俩月有余没写东西了(本来写的就不多,(^▽^)),最近俩月的苦闷,此处省略 1W 字.... 闲言碎语不多讲,使用 Fiddler 有一小段时间了,今天在这里总结下,一来做个笔记,二来可 ...
- Oracle 12c In Memory Option初探
前情提要: Oracle OpenWorld 2013中Larry Ellison爆料的Oracle新特性:Oracle In Memory Database Option 1. 这个新特性将随着12 ...
- Angular初学
简介: angularjs是基本js开发的一个前端类库,主要致力于减轻开发人员在开发Ajax应用过程中的痛苦,适合来做单应用. 客户端模板: Angualr中,模板和数据都会被发送到浏览器中,然后在客 ...
- python之编写购物车(第二天)
作业: 编写购物车 具体实现了如下功能: 1.可购买的商品信息显示 2.显示购物车内的商品信息.数量.总金额 3.购物车内的商品数量进行增加.减少和商品的删除 4.用户余额的充值 5.用户购买完成进行 ...