# ACM-ICPC 2018 沈阳赛区网络预赛

One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are N

JOJO starts from spot S

### Input

There are at most 50

The first line contains two integers N

The second line contains four numbers S, E, K

Then M

It is guaranteed that for any two spots there will be only one directed road from spot A

All the test cases are generated randomly.

### Output

One line containing a sentence. If it is possible for JOJO to arrive at the destination in time, output "yareyaredawa" (without quote), else output "Whitesnake!" (without quote).

#### 样例输入

2 2
1 2 2 14
1 2 5
2 1 4

#### 样例输出

yareyaredawa

#### 题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

k短路模板题

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN = 1100;
const int MAXM = 110000;
const int INF = 0xffffff0;

struct EdgeNode
{
int to;
int w;
int next;
}Edges[MAXM],Edges1[MAXM];

struct Node
{
int to;
int g,f;
bool operator < (const Node &r) const
{
if(r.f == f)
return r.g < g;
return r.f < f;
}
};
int vis[MAXN],Dist[MAXN];

int A_Star(int start,int end,int N,int k)
{
Node e,ne;
int Cnt = 0;
priority_queue<Node> que;
if(start == end)
k++;
if(Dist[start] == INF)
return -1;
e.to = start;
e.g = 0;
e.f = e.g + Dist[e.to];
que.push(e);
while( !que.empty() )
{
e = que.top();
que.pop();
if(e.to == end)
Cnt++;
if(Cnt == k)
return e.g;

for(int i = Head[e.to]; i != -1; i = Edges[i].next)
{
ne.to = Edges[i].to;
ne.g = e.g + Edges[i].w;
ne.f = ne.g + Dist[ne.to];
que.push(ne);
}
}
return -1;
}
void SPFA(int s,int N)
{
for(int i = 0; i <= N; ++i)
Dist[i] = INF;
memset(vis,0,sizeof(vis));
vis[s] = 1;
Dist[s] = 0;
queue<int> Q;
Q.push(s);
while( !Q.empty() )
{
int u = Q.front();
Q.pop();
vis[u] = 0;
for(int i = Head1[u]; i != -1; i = Edges1[i].next)
{
int temp = Dist[u] + Edges1[i].w;
if(temp < Dist[Edges1[i].to])
{
Dist[Edges1[i].to] = temp;
if(!vis[Edges1[i].to])
{
vis[Edges1[i].to] = 1;
Q.push(Edges1[i].to);
}
}
}
}
}

int main()
{
int N,M,u,v,w,s,t,k,S,E,K,T;
while(~scanf("%d%d",&N,&M))
{
scanf("%d%d%d%d",&S,&E,&K,&T);
memset(Edges,0,sizeof(Edges));
memset(Edges1,0,sizeof(Edges1));
for(int i = 0; i < M; ++i)
{
scanf("%d%d%d",&u,&v,&w);
Edges[i].to = v;
Edges[i].w = w;

Edges1[i].to = u;
Edges1[i].w = w;
}
SPFA(E,N);
int kthlenth=A_Star(S,E,N,K);
//printf("%d\n",kthlenth);
if(kthlenth==-1||kthlenth>T)printf("Whitesnake!\n");
else printf("yareyaredawa\n");
}
return 0;
}

F. Fantastic Graph

"Oh, There is a bipartite graph.""Make it Fantastic."

X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up several edges from the current graph and try to make the degrees of every point to between the two boundaries. If you pick one edge, the degrees of two end points will both increase by one. Can you help X to check whether it is possible to fix the graph?

### Input

There are at most 30

For each test case,The first line contains three integers N

The second line contains two numbers L, R

Then K

Note. There may be multiple edges between two vertices.

### Output

One line containing a sentence. Begin with the case number. If it is possible to pick some edges to make the graph fantastic, output "Yes" (without quote), else output "No" (without quote).

#### 样例输入

3 3 7
2 3
1 2
2 3
1 3
3 2
3 3
2 1
2 1
3 3 7
3 4
1 2
2 3
1 3
3 2
3 3
2 1
2 1

#### 样例输出

Case 1: Yes
Case 2: No

#### 题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5+5;
const int maxm=2e5+5;//至少总M*2
const int INF=0x3f3f3f3f;

int TO[maxm],CAP[maxm],NEXT[maxm],tote;
int FIR[maxn],gap[maxn],cur[maxn],d[maxn],q[400000];
int n,m,S,T;

{
//printf("i=%d %d %d %d\n",tote,u,v,cap);
TO[tote]=v;
CAP[tote]=cap;
NEXT[tote]=FIR[u];
FIR[u]=tote++;

TO[tote]=u;
CAP[tote]=0;
NEXT[tote]=FIR[v];
FIR[v]=tote++;
}
void bfs()
{
memset(gap,0,sizeof gap);
memset(d,0,sizeof d);
++gap[d[T]=1];
for(int i=1;i<=n;++i)cur[i]=FIR[i];//当前弧优化
q[1]=T;
{
for(int v=FIR[u];v!=-1;v=NEXT[v])
if(!d[TO[v]])
++gap[d[TO[v]]=d[u]+1],q[++tail]=TO[v];
}
}
int dfs(int u,int fl)
{
if(u==T)return fl;
int flow=0;
for(int &v=cur[u];v!=-1;v=NEXT[v])
if(CAP[v]&&d[u]==d[TO[v]]+1)
{
int Min=dfs(TO[v],min(fl,CAP[v]));
flow+=Min,fl-=Min,CAP[v]-=Min,CAP[v^1]+=Min;
if(!fl)return flow;//当前流完返回
}
if(!(--gap[d[u]]))d[S]=n+1;//出现断层S-T无增广路终止
++gap[++d[u]],cur[u]=FIR[u];
return flow;
}
int ISAP()
{
bfs();//反向最短路
int ret=0;
while(d[S]<=n)ret+=dfs(S,INF);
return ret;
}
void init()//不能忘记
{
tote=0;
memset(FIR,-1,sizeof FIR);
}
bool sol(int L,int R)
{
for(int i=FIR[S];i!=-1;i=NEXT[i])
if(CAP[i])
return false;
for(int i=FIR[T];i!=-1;i=NEXT[i])
if(R-CAP[i^1]<L)
return false;
return true;
}
int main()
{
int N,M,K,L,R,o=1;
while(scanf("%d%d%d",&N,&M,&K)!=EOF)
{
init();
scanf("%d%d",&L,&R);
for(int i=0,u,v;i<K;i++)
{
scanf("%d%d",&u,&v);
}
S=N+M+1,T=S+1,n=T;
for(int i=1;i<=N;i++)
for(int i=N+1;i<=N+M;i++)
int ans=ISAP();
printf("Case %d: %s\n",o++,sol(L,R)?"Yes":"No");
}
return 0;
}

G. Spare Tire

A sequence of integer \lbrace a_n \rbrace

\displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.

Now there are two integers n

\displaystyle \sum_{i=1}^{p}a_{b_i}

But I have no time to solve this problem because I am going to date my boyfriend soon. So can you help me?

### Input

Input contains multiple test cases ( about 15000

### Output

For each test case, print the answer of my question(after mod 1,000,000,007

#### Hint

In the all integers from 1

#### 样例输入

4 4

#### 样例输出

14

#### 题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MD=1e9+7;
int a[20];
ll POW(ll x,ll y)
{
ll ans=1;
for(; y; x=x*x%MD,y>>=1)if(y&1)ans=ans*x%MD;
return ans;
}
int main()
{
ll n,m;
ll tmp=POW(6,MD-2);
while(~scanf("%lld%lld",&n,&m))
{
int tot=0;
ll ans=(n*1LL*(n+1)%MD*(2*n+1)%MD*tmp%MD+(n+1)*n/2)%MD;
for(int i=2; i*i<=m; i++)
{
if(m%i==0)
{
a[tot++]=i;
while(m%i==0)m/=i;
}
}
if(m>1)a[tot++]=m;
int all=1<<tot;
for(int i=1;i<all;i++)
{
int t=1,f=-1;
for(int j=0;j<tot;j++)if(i&(1<<j))t*=a[j],f=-f;
ll g=n/t;
ans=(ans-f*(g*1LL*(g+1)%MD*(2*g+1)%MD*tmp%MD*t%MD*t%MD+(g+1)*g/2*t%MD))%MD;
}
printf("%lld\n",(ans+MD)%MD);
}
return 0;
}

I. Lattice's basics in digital electronics

LATTICE is learning Digital Electronic Technology. He is talented, so he understood all those pieces of knowledge in 10^{-9}

His coding rule is called "prefix code", a type of code system (typically a variable-length code) distinguished by its possession of the "prefix property", which requires that there is no whole code word in the system that is a prefix (initial segment) of any other code word in the system. Note that his code is composed of only 0

LATTICE's device only receives data that perfectly matches LATTICE's rules, in other words, people who send message to LATTICE will always obey his coding rule. However, in the process of receiving data, there are errors that cannot avoid, so LATTICE uses parity check to detect error bytes, after every 8

For example, consider the given data "101010101010101010101010", it should be divided into 3

Data passed the parity check will go into a process that decodes LATTICE's code. The process is described in the following example: consider a situation that, "010"represents 'A' and "1011" represents'B', if the data after parity check is"01010110101011010010", it can be divided into "010"+"1011"+"010"+"1011"+"010"+"010", which means "ABABAA" . LATTICE's device is so exquisite that it can decode all visible characters in the ASCII table .

LATTICE is famous for his Talk show, some reporters have sneaked into his mansion, they stole the data LATTICE to decode in hexadecimal, the coding rule consists of N

### Input

The first line an integer T\ (T<35)

Every test case starts with one line containing two integers, M\ (0<M\leq100000)

Then one line contains data that is going to be received in hexadecimal. (0<|data|<200000)

### Output

For each test case, output the decoded message in a new line, the length of the decoded message should be the same with the length of original characters, which means you can stop decoding having outputted M

### Hint

Lattice's encoding rule for test case 2

ASCII codecharacterlattice's code
49 1 0001
50 2 01001
51 3 011

the device takes this input in hex

1
14DB24722698

input in binary

1
0001 0100 1101 1011 0010 0100 0111 0010 0010 0110 1001 1000

formatted into 6

1
00010100 1
2
10110110 0
3
10010001 1
4
10010001 0
5
01101001 1
6
000

parity check of the third line and the last line failed, so ignore those two lines.parity bits should also be ignored.

1
00010100
2
10110110
3
10010001
4
01101001

arrange those bits by the rules informed

1
0001 01001 011 011 01001 0001 011 01001

output the result

1
12332132

#### 样例输入

2
15 9
32 0100
33 11
100 1011
101 0110
104 1010
108 00
111 100
114 0111
119 0101
A6Fd021171c562Fde1
8 3
49 0001
50 01001
51 011
14DB24722698

#### 样例输出

hello world!!!!
12332132

#### 题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string Ma[257];
int main()
{
Ma['0']="0000",Ma['1']="0001",Ma['2']="0010",Ma['3']="0011";
Ma['4']="0100",Ma['5']="0101",Ma['6']="0110",Ma['7']="0111";
Ma['8']="1000",Ma['9']="1001",Ma['A']="1010",Ma['B']="1011";
Ma['C']="1100",Ma['D']="1101",Ma['E']="1110",Ma['F']="1111";
int T;
cin>>T;
while(T--)
{
int n,k;
cin>>n>>k;
string s;
map<string,int>M;
for(int i=0,x; i<k; i++)
{
cin>>x>>s;
M[s]=x;
}
cin.get();
getline(cin,s);
string c;
for(int i=0; s[i]; i++)
{
if(s[i]>='a'&&s[i]<='z')s[i]-=32;
c.append(Ma[s[i]]);
}
string he;
int l=c.size();
for(int i=0; i<=l-9; i+=9)
{
int t=0;
for(int j=i; j<i+9; j++)t=t^(c[j]-'0');
if(t&1)
{
string fff;
for(int j=i; j<i+8; j++)fff=c[j],he.append(fff);
}
}
string fft,GG;
for(int i=0;he[i];i++)
{
fft+=he[i];
if(M.count(fft))
{
GG+=(char)M[fft];
fft="";
}
}
for(int i=0;i<n;i++)cout<<GG[i];
cout<<"\n";
}
return 0;
}

K. Supreme Number

• 131072K

A prime number (or a prime) is a natural number greater than 1

Now lets define a number N

For example, 17

Now you are given an integer N\ (2 \leq N \leq 10^{100})

### Input

In the first line, there is an integer T\ (T \leq 100000)

In the following T

### Output

For each test case print "Case #x: y", in which x

#### 样例输入

2
6
100

#### 样例输出

Case #1: 5
Case #2: 73

#### 题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

#include <bits/stdc++.h>
using namespace std;
char s[105];
int b[19]={2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
int main()
{
int T,o=0;
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
int l=strlen(s);
if(l>=4) printf("Case #%d: 317\n",++o);
else
{
int a,pos;
sscanf(s,"%d",&a);
for(int i=0;i<19;i++)
if(a>=b[i])
pos=i;
printf("Case #%d: %d\n",++o,b[pos]);
}
}
return 0;
}

B. Call of Accepted

You and your friends are at the table, playing an old and interesting game - the Call of Cthulhu.

There is a mechanism in the game: rolling the dice. You use a notation to communicate the type of dice that needs to be rolled - the operator "\mathop{\rm d}

Formally, for any two integers x, y

Now the game has reached its most exciting stage. You are facing the Great Old One - Cthulhu. Because the spirit has been greatly affected, your sanity value needs to be deducted according to the result of rolling. If the sanity value loses too much, you will fall into madness. As a player, you want to write a program for knowing the minimum and maximum loss of sanity value before rolling, in order to make a psychological preparation.

The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown. ----H. P. Lovecraft

### Input

There are multiple sets of input, at most 30

Each set of input contains a string of only '+''-''*''d''('')' and integers without spaces, indicating the expression of this sanity loss. The length of the expression will be at most 100

It is guaranteed that all expressions are legal, all operators except for '(' and ')' are binary, and all intermediate results while calculating are integers in the range of [-2147483648, 2147483647]

The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far. ----H. P. Lovecraft

### Output

For each set of data, output a line of two integers separated by spaces, indicating the minimum and maximum possible values of the sanity loss.

#### 样例输入

3d6*5
2d3d4

#### 样例输出

15 90
2 24

#### 题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

#include<bits/stdc++.h>
using namespace std;
long long mx,mn;
int calculate(string s)
{
istringstream in('+'+s+'+');
long long total=0,term=0,n;
char op;
while(in>>op)
{
if(op=='+'||op=='-')
{
total+=term;
in>>term;
term*=44-op;
}
else
{
in>>n;
if(op=='*')
term*=n;
else
{
term*=1;
}
}
}
}
string str;
void go()
{
stack<string>sst;
string tmp;
int cal,f=0,o;
sst.push("");
for(int i=0; i<str.length(); i++)
{
if (str[i]=='(')
{
sst.push("");
}
else if(str[i]==')')
{
char ret[40];
cal=calculate(sst.top());
if(cal<0)f=0,cal=-cal;
else f=1;
o=0;
while(cal)
{
ret[o++]=cal%10+'0';
cal=cal/10;
}
if(!f)ret[o++]='-';
ret[o]='\0';
reverse(ret,ret+o);
sst.pop();
sst.top()+=ret;
}
else sst.top()+=str[i];
}
cal=calculate(sst.top());
if(cal>mx)mx=cal;
if(cal<mn)mn=cal;
}
string ss;
void dw(int p)
{
int i;
for(i=p; i<ss.length(); i++)
{
if(ss[i]=='d')
{
str[i]='*';
dw(i+1);
str[i]='d';
dw(i+1);
break;
}
}
if(i==ss.length())
{
go();
}
}
int main()
{
while(cin>>ss)
{
mn=1ll<<32;
mx=-mn;
str=ss;
dw(0);
cout<<mn<<" "<<mx<<endl;
}
}

posted @ 2018-09-08 18:22  暴力都不会的蒟蒻  阅读(...)  评论(...编辑  收藏