Codeforces Round#406 Div.2
A. The Monster
题面
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
题意
a+bi
c+dj
是否有解使他们相等。
暴力。
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b;
cin>>c>>d;
if ((b+d)%2==1 && a%2==0 && c%2==0)
{
cout<<-1;
return 0;
}
if (a<c)
{
swap(a,c);
swap(b,d);
}
for (int i=0;;i++)
{
int x=a*i+b;
if (x>100000)
{
cout<<-1;
return 0;
}
if (x<d) continue;
if ((x-d)%c==0)
{
cout<<x;
return 0;
}
}
}
B. Not Afraid
题面
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one Morty. They're gathering in m groups. Each person can be in many groups and a group can contain an arbitrary number of members.
Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn't considered this possibility).
Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there's a group such that every member in that group is a traitor (they will plan and destroy the world).
Summer knows that if there's a possibility that world ends (there's a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there's at least one scenario (among all 2n possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.
题意
找一组数字中 有没有一对相反数。
代码
#include<bits/stdc++.h>
using namespace std;
int n;
int k;
map<int,int> m;
int main()
{
cin>>n>>k;
for (int i=1;i<=k;i++)
{
m.clear();
int x,y;
bool flag=0;
cin>>x;
for (int o=1;o<=x;o++)
{
cin>>y;
if (m.count(-y)) flag=1;
m[y]=1;
}
if (!flag) return 0*(puts("YES"));
}
return 0*(puts("NO"));
}
C. Berzerk
题面
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.
In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario.
Each one of them has a set of numbers between 1 and n - 1 (inclusive). Rick's set is s1 with k1 elements and Morty's is s2 with k2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.
Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.
题意
A能走一些步数,B能走一些步数。问从k开始谁必赢谁必输?
如果该点下一步就能走到终点,说明这个点必胜。
如果一个人在一个点不能赢了k次说明这个点此人必败。
如果一个人在一个点必败,另一个人走到此点必胜。
代码
//来自紫名玩家 Delsin
#include <bits/stdc++.h>
using namespace std;
int n;
int k1;
int k2;
int a[7010];
int b[7010];
bool loose[2][7010];
bool win[2][7010];
int cntWin[2][7010];
bool mark[2][7010];
void dfs(int node , int turn)
{
for (int i=0;i<(turn?k2:k1);i++)
{
int next=(node+n-(turn?b[i]:a[i]))%n;
if (mark[turn^1][next]) continue;
if (loose[turn][node]) win[turn^1][next]=1;
else if (-- cntWin[turn^1][next] == 0 ) loose[turn^1][next]=1;
else continue;
mark[turn^1][next] = true;
dfs(next,turn^1);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
cin>>k1;
for (int i=0;i<k1;i++) cin>>a[i];
cin>>k2;
for (int i=0;i<k2;i++) cin>>b[i];
loose[0][0] = loose[1][0] = true;
for (int i = 0 ; i < n ; i ++)
cntWin[0][i] = k2 , cntWin[1][i] = k1;
mark[0][0] = mark[1][0] = true;
dfs(0,1),dfs(0,0);
for (int x = 1 ; x < n ; x ++ , cout << " ")
{
if (!win[1][x] && !loose[1][x]) cout << "Loop";
else if (win[1][x]) cout << "Win";
else cout << "Lose";
}
cout<<endl;
for (int x = 1 ; x < n ; x ++ , cout << " ")
{
if (!win[0][x] && !loose[0][x]) cout << "Loop";
else if (win[0][x]) cout << "Win";
else cout << "Lose";
}
}
D. Legacy
题面
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.
There are n planets in their universe numbered from 1 to n. Rick is in planet number s (the earth) and he doesn't know where Morty is. As we all know, Rick owns a portal gun. With this gun he can open one-way portal from a planet he is in to any other planet (including that planet). But there are limits on this gun because he's still using its free trial.
By default he can not open any portal by this gun. There are q plans in the website that sells these guns. Every time you purchase a plan you can only use it once but you can purchase it again if you want to use it more.
Plans on the website have three types:
- 1.With a plan of this type you can open a portal from planet v to planet u.
- 2.With a plan of this type you can open a portal from planet v to any planet with index in range [l, r].
- 3.With a plan of this type you can open a portal from any planet with index in range [l, r] to planet v.
Rick doesn't known where Morty is, but Unity is going to inform him and he wants to be prepared for when he finds and start his journey immediately. So for each planet (including earth itself) he wants to know the minimum amount of money he needs to get from earth to that planet.
题意
有三种路
- 直达路
- u到l,r的路
- l,r到u的路
单源最短路径是多少
官方题解
把一个区间看作是一个新的节点,并且与原来的节点连接,那么用两个线段树重建图,一个区间连向点,一个点连向区间,求新图的单源最短路径。
代码
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n,m,s;
class road{
public:
int to,next;
ll dis;
}r[8*1000010];
int cnt;
int totnode;
ll t1[4*100010];
ll t2[4*100010];
ll d[4*100010];
int first[4*100010];
const ll INF=1e17;
int op;
int opu,opl,opr,opw;
queue<int> q;
int in[4*100010];
void addroad(int u,int v,ll dis)
{
++cnt;
r[cnt].next=first[u];
first[u]=cnt;
r[cnt].to=v;
r[cnt].dis=dis;
}
void build(int l,int r,int o)
{
if (l==r)
{
t1[o]=t2[o]=l;
return;
}
int mid=(l+r)>>1;
build(l,mid,o<<1);
build(mid+1,r,o<<1|1);
t1[o] = ++totnode; t2[o]=++totnode;
addroad(t1[o],t1[o<<1],0); addroad(t2[o<<1],t2[o],0);
addroad(t1[o],t1[o<<1|1],0); addroad(t2[o<<1|1],t2[o],0);
return ;
}
void findtree(int L,int R,int l,int r,int o)
{
if (l>=L && r<=R)
{
addroad(opu,t1[o],opw);
return;
}
int mid=(l+r)>>1;
if (L<=mid) findtree(L,R,l,mid,o<<1);
if (R>=mid+1) findtree(L,R,mid+1,r,o<<1|1);
}
void findtree2(int L,int R,int l,int r,int o)
{
if (l>=L && r<=R)
{
addroad(t2[o],opu,opw);
return;
}
int mid=(l+r)>>1;
if (L<=mid) findtree2(L,R,l,mid,o<<1);
if (R>=mid+1) findtree2(L,R,mid+1,r,o<<1|1);
}
void spfa()
{
while (!q.empty())
{
int u=q.front();q.pop();
in[u]=0;
for (int i=first[u];i;i=r[i].next)
{
int v=r[i].to;
if (d[v] > d[u] + r[i].dis)
{
d[v] = d[u] + r[i].dis;
if (!in[v])
{
q.push(v);
in[v]=1;
}
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>s;
totnode=n;
build(1,n,1);
for (int i=1;i<=m;i++)
{
cin>>op;
if (op==1)
{
cin>>opu>>opl>>opw;
addroad(opu,opl,opw);
}
if (op==2)
{
cin>>opu>>opl>>opr>>opw;
findtree(opl,opr,1,n,1);
}
if (op==3)
{
cin>>opu>>opl>>opr>>opw;
findtree2(opl,opr,1,n,1);
}
}
for (int i=1;i<=totnode;i++) d[i]=INF;
d[s]=0;
in[s]=1;
q.push(s);
spfa();
for (int i=1;i<=n;i++,cout<<" ") if (d[i]<INF) cout<<d[i];else cout<<"-1";
}
E
题面
题意
代码
//
比赛链接
posted on 2017-05-23 04:06 EDGsheryl 阅读(1028) 评论(0) 编辑 收藏 举报