A. Bachgold Problem
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).

Output

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.

Examples
input
5
output
2
2 3
input
6
output
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 ;
}
B. Parallelogram is Back
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Example
input
0 0
1 0
0 1
output
3
1 -1
-1 1
1 1
Note

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 ;
}
C. Voting
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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:

  1. 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).
  2. 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.
  3. 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.
  4. 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.

Input

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.

Output

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

Examples
input
5
DDRRR
output
D
input
6
DDRRRR
output
R
Note

Consider one of the voting scenarios for the first sample:

  1. Employee 1 denies employee 5 to vote.
  2. Employee 2 denies employee 3 to vote.
  3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
  4. Employee 4 denies employee 2 to vote.
  5. Employee 5 has no right to vote and skips his turn (he was denied by employee 1).
  6. Employee 1 denies employee 4.
  7. 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 ;
}
D. Leaving Auction
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
6
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
3
1 3
2 2 3
2 1 2
output
2 100000
1 10
3 1000
input
3
1 10
2 100
1 1000
2
2 1 2
2 2 3
output
0 0
1 10
Note

Consider the first sample:

  • In the first question participant number 3 is absent so the sequence of bids looks as follows:
    1. 1 10
    2. 2 100
    3. 1 10 000
    4. 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. 1 10
    2. 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:
    1. 3 1 000
    2. 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的更多相关文章

  1. Codeforces Round #388 (Div. 2)

      # Name     A Bachgold Problem standard input/output 1 s, 256 MB    x6036 B Parallelogram is Back s ...

  2. Codeforces Round #388 (Div. 2) - C

    题目链接:http://codeforces.com/contest/749/problem/C 题意:给定一个长度为n的D/R序列,代表每个人的派别,然后进行发表意见,顺序是从1到n.每个人到他的回 ...

  3. Codeforces Round #388 (Div. 2) - B

    题目链接:http://codeforces.com/contest/749/problem/B 题意:给定平行四边形的3个点,输出所有可能的第四个点. 思路:枚举任意两个点形成的直线,然后利用这两个 ...

  4. Codeforces Round #388 (Div. 2) - A

    题目链接:http://codeforces.com/contest/749/problem/A 题意:给定一个数n,求把n分解成尽量多的素数相加.输入素数个数和具体方案. 思路:因为要尽量多的素数, ...

  5. Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)

    题目大意 给定一个1到n的排列,然后随机选取一个区间,让这个区间内的数随机改变顺序,问这样的一次操作后,该排列的逆序数的期望是多少 首先,一个随机的长度为len的排列的逆序数是(len)*(len-1 ...

  6. 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 ...

  7. Codeforces Round #388 (Div. 2) A+B+C!

    A. Bachgold Problem 任何一个数都可以由1和2组成,由于n是大于等于2的,也就是可以由2和3组成.要求最多的素数即素数越小越好,很明显2越多越好,如果n为奇数则再输出一个3即可. i ...

  8. Codeforces Round #388 (Div. 2) C. Voting

    题意:有n个人,每个人要么是属于D派要么就是R派的.从编号1开始按顺序,每个人都有一次机会可以剔除其他任何一个人(被剔除的人就不在序列中也就失去了剔除其他人的机会了):当轮完一遍后就再次从头从仅存的人 ...

  9. 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 ...

随机推荐

  1. shell脚本一

    在一些复杂的Linux维护工作中,大量重复的输入和交互操作不但费时费力,容易出错.这时候就需要用到脚本. 编写脚本的好处:  批量的处理,自动化的完成维护,减轻管理员的负担. linux的shell脚 ...

  2. django的分页

    一.分页器的函数封装 # 分页计算最小页和最大页 def page_list_return(total, current=1): ''' 分页,返回本次分页的最小页数和最大页数列表 :param to ...

  3. Access restriction: The type QName is not accessible due to restriction on required library

    There's another solution that also works. I found it on this forum: Go to the Build Path settings in ...

  4. PHP的启动与终止

    1.2 PHP的启动与终止 PHP程序的启动可以看作有两个概念上的启动,终止也有两个概念上的终止. 其中一个是PHP作为Apache(拿它举例,板砖勿扔)的一个模块的启动与终止, 这次启动php会初始 ...

  5. 找出A字符串中出现B字符串的起始位置

    /** * 找出B出现在A中的起始位置 * @param A * @param lenA * @param B * @param lenB * @date 2016-10-7 * @author sh ...

  6. PHP 使用编码树,生成easyui中的tree样式

    生成树的时候,数据库中一般设计的都为无级数,即为:父子节点的树,例如:基本的数据表设计为: nodecode 节点编码 parentnodecode 父节点编码 nodename  节点名称 这样的形 ...

  7. Samba文件服务器详细配置步骤

    准备安装 环境:CentOS 6.3_x64bit 安装:Minimal(最小) 1.配置IP地址 2.挂载:[root@localhost ~]# mount -t iso9660 /dev/cdr ...

  8. 一个python的计算熵(entropy)的函数

    计算熵的函数: # -*- coding: utf-8 -*- import math #the function to calculate entropy, you should use the p ...

  9. 删除txt文件每行第一(n)个空格前内容的方法

    1. 把要处理的文本保存在a.txt文件中 2. 在相同文件夹中新建一个xx.txt文件,输入下面代码,再把文件名改为xx.bat. @echo offset fn=a.txt(for /f &quo ...

  10. android使用ksoap2调用sap的webservice

    public void on_clicked(View view) { Thread webserviceThread = new Thread() { public void run() { Str ...