Codeforces Round #388 (Div. 2)
| # | Name | ||
|---|---|---|---|
| A |
standard input/output
1 s, 256 MB |
||
| B |
standard input/output
1 s, 256 MB |
||
| C |
standard input/output
1 s, 256 MB |
||
| D |
standard input/output
2 s, 256 MB |
||
| E |
standard input/output
1 s, 256 MB |
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)的更多相关文章
- 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) A,B,C,D
A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
随机推荐
- DevExpress免费公开课,讲解即将发布的16.2新版功能
先报名后听课,开课时间12月底 报名地址:http://training.evget.com/open/detail/5115[适合人群]覆盖全领域,尤其适合课程适用人群:软件开发人员.企业中的数据分 ...
- iOS - GitHub干货分享(APP引导页的高度集成 - DHGuidePageHUD - ②)
距上一篇博客"APP引导页的高度集成 - DHGuidePageHUD - ①"的发布有一段时间了, 后来又在SDK中补充了一些新的内容进去但是一直没来得及跟大家分享, 今天来跟大 ...
- (十三)Maven插件解析运行机制
这里给大家详细说一下Maven的运行机制,让大家不仅知其然,更知其所以然. 1.插件保存在哪里? 与我们所依赖的构件一样,插件也是基于坐标保存在我们的Maven仓库当中的.在用到插件的时候会先从本地仓 ...
- freeswitch嵌入python脚本
操作系统:debian8.5_x64 freeswitch 版本 : 1.6.8 python版本:2.7.9 开启python模块 安装python lib库 apt-get install pyt ...
- 无刷新读取数据库 (ajax)
<html> <head> <script type="text/javascript"> function loadXMLDoc() { va ...
- 远程管理无管理员权限的PC客户端
一.简介 为提高操作系统稳定性.流畅度,分公司同事PC用户没有administrator权限,导致同事不能对系统进行设置.不能自行安装软件.网管使用远程管理软件(如Teamviewer.QQ)为同事提 ...
- 解析opencv中Box Filter的实现并提出进一步加速的方案(源码共享)。
说明:本文所有算法的涉及到的优化均指在PC上进行的,对于其他构架是否合适未知,请自行试验. Box Filter,最经典的一种领域操作,在无数的场合中都有着广泛的应用,作为一个很基础的函数,其性能的好 ...
- everything + autohotkey的配合使用
一,everything是文件搜索神奇,瞬间定位到文件,在众多的文件中找到你需要的文件.(百度下载就好,分32位和64位) 二,autohotkey是热键启动设置,方便的打开常用的应用. 直接使用 ...
- JS中字符串的true转化为boolean类型的true
var a="True"; a = eval(a.toLowerCase()); alert(typeof a); //boolean alert(a);//true 正解,eva ...
- 嵌入式Linux驱动学习之路(二十五)虚拟网卡驱动程序
一.协议栈层次对比 设备无关层到驱动层的体系结构 1).网络协议接口层向网络层协议提供提供统一的数据包收发接口,不论上层协议为ARP还是IP,都通过dev_queue_xmit()函数发送数据,并通过 ...