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 ...
随机推荐
- XML和JSON数据格式对比
概念 XML 扩展标记语言 (Extensible Markup Language, XML) ,用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语 ...
- Nodejs express 文件上传
文件上传 以下我们创建一个用于上传文件的表单,使用 POST 方法,表单 enctype 属性设置为 multipart/form-data. index.htm 文件代码修改如下: <html ...
- 夺命雷公狗----Git---7---GitHub当仓库本地使用(完)
首先我们将github上的东西克隆到本地: 然后在本地创建一个文件夹,然后进入git命令行: 成功后如下所示: 将仓库里面的内容给克隆到本地了... 然后创建一个index.html然后添加进去: 在 ...
- iOS当中一些常见的面试题
转自各方面..... 一.前言部分 文中的问题多收集整理自网络,不保证100%准确,还望斟酌采纳. 1.iOS9有哪些新特性? 答案: 1)改进了 Siri 基于日期.位置和相簿名称来搜索个人照片和视 ...
- MI卡UID
卡号是根据第0扇区第0块的UID,高位和低位互换后转10进制后出的数字.一般读卡器都会在左边补0补足10位.
- php就业网版本已改版成功
php就业网简介:www.php91.net,专注于Thinkphp框架教程的php框架学习中心.同时也有小崔老师自学php的教程,与你一起成长哦 同时,php就业网教程部分:http://www.p ...
- xampp修改mysql默认密码详解
在这里介绍xampp修改mysql默认密码的大概过程是先利用xampp的phpmyadmin进入修改mysql密码,修改之后我们再修改xampp中phpmyadmin的密码,这样就完整的修改mysql ...
- 模块(configparser+shutil+logging)
一.configparser模块 1.模块介绍 configparser用于处理特定格式的文件,其本质上是利用open来操作文件. *注:(这里解释一下特定格式的文件) a.有section和opti ...
- window 常用快捷键
1.新建文件夹 ctrl+shift+n 2.删除文件夹 ctrl+d 3.打开命令行 窗口+r 4.关闭命令行 命令行内输入exit然后回车 5.快捷键操作浏览器 1)ctrl+w关闭当前标 ...
- Computed read-only property vs function in Swift
In the Introduction to Swift WWDC session, a read-only property description is demonstrated: class V ...