Atcoder Grand-014 Writeup
A - Cookie Exchanges
题面
Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:
Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.
This action will be repeated until there is a person with odd number of cookies in hand.
How many times will they repeat this action? Note that the answer may not be finite.
题意
三个人,每次把自己的饼干分成两份给其他两个人。模拟,map判断是否循环。
代码
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int> , int > m;
int a[5];
int b[5];
int ans;
int cmp(int q,int w)
{
return q<w;
}
int main()
{
cin>>a[0]>>a[1]>>a[2];
while (1)
{
sort(a,a+3,cmp);
if (a[0]%2 || a[1]%2 || a[2]%2)
{
cout<<ans<<endl;
return 0;
}
if (m.count(make_pair(a[0],a[1])) && m[make_pair(a[0],a[1])]==a[2]) return 0*puts("-1");
m[make_pair(a[0],a[1])]=a[2];
b[0]=(a[1]+a[2])/2;
b[1]=(a[0]+a[2])/2;
b[2]=(a[1]+a[0])/2;
for (int i=0;i<3;i++) a[i]=b[i];
ans++;
}
}
B - Unplanned Queries
题面
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
Increment the number written at each edge along the path connecting vertices ai and bi, by one.
After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.
Determine whether there exists a tree that has the property mentioned by Takahashi.
题意
给出n个点和m条路(不一定直达),经过的路会+1,是否能构造一个图,使得m条路走完后,所有的路都是偶数。
代码
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int m,x,y;
int main()
{
cin>>n>>m;
for (int i=1;i<=m;i++)
{
cin>>x>>y;
++a[x],++a[y];
}
for (int i=1;i<=n;i++) if (a[i]%2) return 0*puts("NO");
return 0*puts("YES");
}
C - Closed Rooms
题面
Takahashi is locked within a building.
This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character Ai,j. If Ai,j= #, the room is locked and cannot be entered; if Ai,j= ., the room is not locked and can be freely entered. Takahashi is currently at the room where Ai,j= S, which can also be freely entered.
Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i−1,j), (i+1,j), (i,j−1) and (i,j+1).
Takahashi will use his magic to get out of the building. In one cast, he can do the following:
Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered.
Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on.
His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so.
It is guaranteed that Takahashi is initially at a room without an exit.
题意
给出一个迷宫,每次S能走k个白格子,然后走k个锁,问需要几个阶段S能逃走。
官方题解
先走到所有能走到的格子,不大于k也不解锁,ans=1+ceil(min(y-1,x-1,h-x,w-y)/k)
代码
#include <bits/stdc++.h>
using namespace std;
const int fx[] = { 0, 1, 0,-1};
const int fy[] = { 1, 0,-1, 0};
int n,m,k,sx,sy;
char s[1010];
bool b[1010][1010];
bool a[1010][1010];
bool flag;
queue<pair<int,int> > q;
queue<int> qs;
int main()
{
cin>>n>>m>>k;
for (int i=1;i<=n;i++)
{
scanf("%s",s+1);
for (int j=1;j<=m;j++) a[i][j] = s[j]!='#';
for (int j=1;j<=m;j++) if (s[j]=='S') sx=i, sy=j;
}
if (sx == 1 || sx == n || sy == 1 || sy == m) return puts("0"), 0;
b[sx][sy] = 1;
q.push(make_pair(sx,sy));
qs.push(0);
while (!q.empty()) {
int ux = q.front().first;
int uy = q.front().second;
q.pop();
int us = qs.front(); qs.pop();
if (us == k) continue;
if (ux == 1 || ux == n || uy == 1 || uy == m) flag = 1;
for (int i=0;i<4;i++)
{
int vx = ux + fx[i], vy = uy + fy[i];
if (vx<1 || vx>n || vy<1 || vy>m) continue;
if (!b[vx][vy] && a[vx][vy])
{
b[vx][vy] = 1;
q.push(make_pair(vx,vy));
qs.push(us+1);
}
}
}
if (flag) return puts("1"), 0;
int ans = 2147483647;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if (b[i][j])
{
int t = min( min(i-1,j-1) , min(n-i,m-j) );
int cur = (t+k-1) / k;
ans = min(ans, cur+1);
}
cout << ans << endl;
return 0;
}
D - Black and White Tree
题面
There is a tree with N vertices numbered 1 through N. The i-th of the N−1 edges connects vertices ai and bi.
Initially, each vertex is uncolored.
Takahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform the following operation, starting from Takahashi:
Select a vertex that is not painted yet.
If it is Takahashi who is performing this operation, paint the vertex white; paint it black if it is Aoki.
Then, after all the vertices are colored, the following procedure takes place:
Repaint every white vertex that is adjacent to a black vertex, in black.
Note that all such white vertices are repainted simultaneously, not one at a time.
If there are still one or more white vertices remaining, Takahashi wins; if all the vertices are now black, Aoki wins. Determine the winner of the game, assuming that both persons play optimally.
题意
先手执白,后手执黑,全染色后黑色将相邻染黑,全黑后手胜,问存不存在后手必胜的情况。
树的完备匹配。
代码
#include <bits/stdc++.h>
using namespace std;
vector<int> e[1000500];
int p[1000500];
int n;
void link(int a,int b)
{
e[a].push_back(b);
e[b].push_back(a);
}
void dfs(int u,int fa)
{
for (int i=0;i<e[u].size();i++)
{
int v=e[u][i];
if (v==fa) continue;
dfs(v,u);
}
if (!p[u] && !p[fa]) p[u] = p[fa] = 1;
}
int main() {
cin>>n;
for (int i=1;i<n;i++)
{
int x,y;
cin>>x>>y;
link(x,y);
}
p[0] = 1;
dfs(1,0);
int ans = 1;
for (int i=1;i<=n;i++) if (!p[i]) ans = 0;
puts(!ans?"First":"Second");
return 0;
}
E - Blue and Red Tree
题意
不清
F - Strange Sorting
题面
Takahashi loves sorting.
He has a permutation (p1,p2,…,pN) of the integers from 1 through N. Now, he will repeat the following operation until the permutation becomes (1,2,…,N):
First, we will define high and low elements in the permutation, as follows. The i-th element in the permutation is high if the maximum element between the 1-st and i-th elements, inclusive, is the i-th element itself, and otherwise the i-th element is low.
Then, let a1,a2,…,ak be the values of the high elements, and b1,b2,…,bN−k be the values of the low elements in the current permutation, in the order they appear in it.
Lastly, rearrange the permutation into (b1,b2,…,bN−k,a1,a2,…,ak).
How many operations are necessary until the permutation is sorted?
题意
把每次第一个开头的递增子序列取出,放在最后面,问几次能排好序列。
官方题解
思考过程:如果拿掉1,发现序列变化过程,基本相似。但是还是要参考1,如果最后例如2,3,……,1,……,n-1,n。则T=T+1;
那我们很容易想到去递推。
如果一个序列,i,i+1,i+2这种连一起的,我们可以看作一个整体。
对于(a,b,c),a<b<c。我们认为(a,b,c)=(b,c,a)=(c,a,b) 因为他们做整体变换,不消耗次数。
如果出现其他状况,如c,b,a。那么就需要移动了。移动后,bc就作为一个整体,变成,(b,a)需要处理
代码
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int q[200010];
int T[200010];
int f[200010];
int n;
int cnt;
int main()
{
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++) q[a[i]]=i;
for (int i=n-1;i;i--)
{
if( !T[ i + 1 ] )
{
if( q[i] > q[i+1] ) T[i]=1, f[i]=i+1;
else T[i] = 0;
}
else
{
int cnt = 0;
cnt += q[f[i+1]] < q[i];
cnt += q[i] < q[i+1];
cnt += q[i+1] < q[f[i+1]];
if (cnt==2) T[i]=T[i+1],f[i]=f[i+1];
else T[i]=T[i+1]+1,f[i]=i+1;
}
}
cout<<T[1];
}
赛后总结
自己还是太菜了qwq
只会两题,第三题没想进去,第四题发现了一种结论,但是打不来。
要抓紧订正题目,搞了半天还有一堆题目坑没填。
比赛链接
http://agc014.contest.atcoder.jp
Atcoder Grand-014 Writeup的更多相关文章
- AtCoder Grand Contest 014
AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中 ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
- AtCoder Grand Contest 005
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
随机推荐
- windows2003两台服务器,局域网之间不能互相访问
准备在两台服务器之间,映射网络驱动器,但怎么也连不上了. 可以在网络邻居中看到对方的机器,但就是访问不到共享的文件,也无法做网络映射. 搜索了一下,发现在是因为防火墙中,没有把"文件和打印机 ...
- snort帮助文档
[1] CentOS6.6下基于snort+barnyard2+base的入侵检测系统的搭建 2 基于Snort的C_S模式的IDS的设计与应用_王会霞.caj [3] Snort 笔记1 - 3种模 ...
- NOI导刊 2018河南郑州游记
前言 本蒟蒻来自浙江的弱市弱校,因为不想两年\(OI\)一场空,以及想出去玩,所以与同届大佬一起报了\(NOI\)导刊,希望能留下点不错的记忆吧. \(Day\ 0\) \(10\)月\(1\)日 经 ...
- BZOJ2730 [HNOI2012]矿场搭建 - Tarjan割点
Solution 输入中没有出现过的矿场点是不用考虑的, 所以不用考虑只有 一个点 的点双联通分量. 要使某个挖矿点倒塌, 相当于割去这个点, 所以我们求一遍割点和点双联通分量. 之后的点双联通分量构 ...
- 用 Python 写 Robot Framework 测试
Robot Framework 框架是基于 Python 语言开发的,所以,它本质上是 Python 的一个库. 1.你懂 Python 语言. 2.又想使用 Robot Framework 测试框架 ...
- netty1 快速入门
Netty是一个高性能.异步事件驱动的网路通信框架 ,由于精力有限,本人并没有对其源 码做了特别细致的研究.如果下面的内容有错误或不严谨的地方,也请大家指正和谅解. Netty的线程模型是Reacto ...
- win32 注册表操作
创建键 RegCreateKeyEx int SetRecordVideoSavedDays(int newSavedDays) { HKEY hSubKey = NULL; LONG lRet = ...
- spring boot所有配置
转载 http://blog.csdn.net/lpfsuperman/article/details/78287265 # 日志配置# 日志配置文件的位置. 例如对于Logback的`classpa ...
- 利用HBuilder开发基于MUI的H5+ app中使用百度地图定位功能
定位功能有两种方法: 首先要初始化内置地图: var map = new plus.maps.Map("map"); 这里黄色的map是html里面的id: <div id= ...
- 使用SpringMVC的@CrossOrigin注解解决跨域请求问题
跨域问题,通俗说就是用ajax请求其他站点的接口,浏览器默认是不允许的.同源策略(Same-orgin policy)限制了一个源(orgin)中加载脚本或脚本与来自其他源(orgin)中资源的交互方 ...