# Name    
A
standard input/output

1 s, 256 MB

   x6036
B
standard input/output

1 s, 256 MB

   x4139
C
standard input/output

1 s, 256 MB

   x2671
D
standard input/output

2 s, 256 MB

   x1113
E
standard input/output

1 s, 256 MB

   x247
 

A. Bachgold Problem

给出一个N,请你找出一些素数,使得素数的和为N,且素数的个数最多。注意,素数可以重复,而且N>=2。

解:显然用2和3拆喽,大家又不傻。

 VAR
n:longint;
a:longint;
i:longint;
BEGIN
readln(n);
a:=n div ;
writeln(a);
for i:= to a- do begin
write();
write(' ');
end;
write(+n mod );
END.

B. Parallelogram is Back

给出一个平行四边形的三个顶点,输出所有可能的第四个顶点。

解:小学几何问题喽,大家又不傻。

 #include <bits/stdc++.h>

 using namespace std;

 signed main(void)
{
int x1, y1;
int x2, y2;
int x3, y3;
cin >> x1 >> y1
>> x2 >> y2
>> x3 >> y3;
cout << << endl;
cout << +x1 - x2 + x3 << " " << +y1 - y2 + y3 << endl;
cout << +x1 + x2 - x3 << " " << +y1 + y2 - y3 << endl;
cout << -x1 + x2 + x3 << " " << -y1 + y2 + y3 << endl;
}

C. Voting

两个政党(D和R)的议员们在进行投票,他们的投票规则十分古怪:当前投票的议员,可以选取一个队里阵营的议员,取消他的投票权。

所有议员按照给出的顺序循环投票,最终以一个阵营的全部议员都被禁言结束,此时另一个阵营就会胜出。如果议员们都按照最优策略投票,请你模拟出投票的结果。

解:用两个队列维护两个政党的议员的位置,每次取出两个队首进行比较,位置在前的议员可以弹掉另一个队首,这个队首再也不会进队,而位置在前的议员以当前位置+n的新位置(循环)加入队尾。

 #include <bits/stdc++.h>

 using namespace std;

 int n;
string s;
queue<int> D, R; signed main(void)
{
cin >> n >> s; for (int i = ; i < n; ++i)
(s[i] == 'D' ? D : R).push(i); while (!D.empty() && !R.empty())
{
if (D.front() < R.front())
R.pop(), D.push(D.front() + n), D.pop();
else
D.pop(), R.push(R.front() + n), R.pop();
} cout << (D.empty () ? 'R' : 'D') << endl;
}

D. Leaving Auction

一些壕在拍卖会上竞拍,首先给出了大家既定的报价。一个人可能给出多次报价,但不会自己无故压自己。有Q次询问,每次一些人会离场,请把这些人的报价从序列中清除,问最后谁以什么价格赢得拍品。赢家即为最后一个报价的人,而价格为其最低的压过其他所有人(在场)的价格。如果有不理解,可以看样例。

解:首先处理出所有壕的最后一个报价,然后排序。每次询问可以暴力在序列中找到没有离场的最靠后报价的壕,那么他一定会赢得拍品,问题在于是什么价格。我们需要知道他需要压住的最后的另一位壕(如果存在),这个可以继续在序列中暴力向前扫描得到(因为总的离场人数是有限制的,而至多扫过的位置是离场人数级别的,所以复杂度有保证)。我们现在需要知道赢家壕在这位壕最后一次出价的位置之后,出的第一次价。如果事先维护了每个人的出价位置,直接在序列中二分即可,复杂度可以过。注意不要像我一样每次询问memset一遍awy数组,会TLE on test8。

 #include <bits/stdc++.h>

 #define fread_siz 1024

 inline int get_c(void)
{
static char buf[fread_siz];
static char *head = buf + fread_siz;
static char *tail = buf + fread_siz; if (head == tail)
fread(head = buf, , fread_siz, stdin); return *head++;
} inline int get_i(void)
{
register int ret = ;
register int neg = false;
register int bit = get_c(); for (; bit < ; bit = get_c())
if (bit == '-')neg ^= true; for (; bit > ; bit = get_c())
ret = ret * + bit - ; return neg ? -ret : ret;
} using namespace std; const int N = ; int n, m; int a[N], b[N]; int tot;
int vis[N];
int lst[N];
int ord[N]; int awy[N], q; vector<int> p[N]; signed main(void)
{
n = get_i(); for (int i = ; i <= n; ++i)
a[i] = get_i(),
b[i] = get_i(); for (int i = ; i <= n; ++i)
p[a[i]].push_back(i); for (int i = n; i >= ; --i)
if (!vis[a[i]])
{
vis[a[i]] = ;
lst[a[i]] = i;
ord[++tot] = a[i];
} m = get_i(); for (int i = ; i <= m; ++i)
{
q = get_i();
for (int j = ; j <= q; ++j)
awy[get_i()] = i;
int ans1 = , ans2 = , pos;
for (int j = ; j <= tot && !ans1; ++j)
if (awy[ord[j]] != i)ans1 = ord[j], pos = j;
if (!ans1)
puts("0 0");
else
{
for (++pos; pos <= tot; ++pos)
if (awy[ord[pos]] != i)break;
if (pos > tot)
printf("%d %d\n", ans1, b[p[ans1][]]);
else
{
int lim = lst[ord[pos]];
ans2 = *lower_bound(begin(p[ans1]), end(p[ans1]), lim);
printf("%d %d\n", ans1, b[ans2]);
}
}
}
}

E题看起来好烦,无限期停更,大概不会填坑。

@Author: YouSiki

Codeforces Round #388 (Div. 2)的更多相关文章

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

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

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

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

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

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

  4. Codeforces Round #388 (Div. 2) A,B,C,D

    A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...

  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. Eclipse安装Spring-tool-suite

    目录结构: // contents structure [-] 在Eclipse上安装Spring-tool-suite的方法有那些 如何查看自己的Eclipse版本 如何知道自己的Eclipse对应 ...

  2. 节日来了发个HTML5红包

    效果图: 请关注微信公众号 何问起 , 账号ihewenqi ,或者微信扫描下图二维码: 关注后发送 愚人节 ,或 微信节日红包 ,可以体验效果. 代码如下: <!DOCTYPE html> ...

  3. AlloyTouch Button插件-不再愁click延迟和点击态

    移动端不能使用click,因为click会有300ms.所有有了fastclick这样的解决方案.然后fastclick并没有解决点击态(用户点击的瞬间要有及时的外观变化反馈)的问题.hover会有不 ...

  4. zepto/jQuery、AngularJS、React、Nuclear的演化

    写在前面 因为zepto.jQuery2.x.x和Nuclear都是为现代浏览器而出现,不兼容IE8,适合现代浏览器的web开发或者移动web/hybrid开发.每个框架类库被大量用户大规模使用都说明 ...

  5. Dynamics CRM 之ADFS 使用 SQL Server 的联合服务器场

    此拓扑用于 Active Directory 联合身份验证服务 (AD FS) 不同于使用 Windows 内部数据库 (WID) 部署拓扑,因为不会将数据复制到每台联合服务器场中的联合身份验证服务器 ...

  6. 获得设备的唯一标识符UDID

    在IOS5之后,苹果为避免根据UDID获得用户的信息,而禁止使用uniqueIdentifier获得UDID,但是仍有些应用需要根据UDID区分设备 有一个系统的库IOKit.framework可以获 ...

  7. ListView之点击展开菜单

    一.概述 ListView点击item显示菜单是要实现这样的效果: 需要实现的逻辑如下: 1)点击一个普通item,展开当前菜单,同时关闭其他菜单 2)点击一个已展开的菜单,隐藏当前菜单 3)将展开菜 ...

  8. xhtml、html与html5的区别

    一.基本概念: html:超文本标记语言 (Hyper Text Markup Language) xhtml:可扩展超文本标记语言,是一种置标语言,表现方式与超文本标记语言(HTML)类似,不过语法 ...

  9. angularJS 学习演示

    开源网址(带中文说明注释):https://github.com/EnhWeb/angularJS.git

  10. es6

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...