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

D. Made In Heaven

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 NN spots in the jail and MM roads connecting some of the spots. JOJO finds that Pucci knows the route of the former (K-1)(K1)-th shortest path. If Pucci spots JOJO in one of these K-1K1routes, Pucci will use his stand Whitesnake and put the disk into JOJO's body, which means JOJO won't be able to make it to the destination. So, JOJO needs to take the KK-th quickest path to get to the destination. What's more, JOJO only has TT units of time, so she needs to hurry.

JOJO starts from spot SS, and the destination is numbered EE. It is possible that JOJO's path contains any spot more than one time. Please tell JOJO whether she can make arrive at the destination using no more than TT units of time.

Input

There are at most 5050 test cases.

The first line contains two integers NNand M(1 \leq N \leq 1000, 0 \leq M \leq 10000)(1N1000,0M10000). Stations are numbered from 11 to NN.

The second line contains four numbers S, E, KS,E,K and TT ( 1 \leq S,E \leq N1S,EN, S \neq ESE, 1 \leq K \leq 100001K10000, 1 \leq T \leq 1000000001T100000000 ).

Then MM lines follows, each line containing three numbers U, VU,V and W(1 \leq U,V \leq N, 1 \leq W \leq 1000)(1U,VN,1W1000) . It shows that there is a directed road from UU-th spot to VV-th spot with time WW.

It is guaranteed that for any two spots there will be only one directed road from spot AA to spot B(1 \leq A,B \leq N, A \neq B)(1A,BN,AB), but it is possible that both directed road <A,B><A,B> and directed road <B,A><B,A> exist.

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];

int Head[MAXN],Head1[MAXN];

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));
        memset(Head,-1,sizeof(Head));
        memset(Head1,-1,sizeof(Head1));
        for(int i = 0; i < M; ++i)
        {
            scanf("%d%d%d",&u,&v,&w);
            Edges[i].to = v;
            Edges[i].w = w;
            Edges[i].next = Head[u];
            Head[u] = i;

            Edges1[i].to = u;
            Edges1[i].w = w;
            Edges1[i].next = Head1[v];
            Head1[v] = i;
        }
        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 3030 test cases.

For each test case,The first line contains three integers NN the number of left part graph vertices, MM the number of right part graph vertices, and KK the number of edges ( 1 \le N \le 20001N2000,0 \le M \le 20000M2000,0 \le K \le 60000K6000 ). Vertices are numbered from 11 to NN.

The second line contains two numbers L, RL,(0 \le L \le R \le 300)(0LR300). The two fantastic numbers.

Then KK lines follows, each line containing two numbers UU, V(1 \le U \le N,1 \le V \le M)(1UN,1VM). It shows that there is a directed edge from UU-th spot to VV-th spot.

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 沈阳赛区网络预赛

写了个网络流,然后大家贪心什么的,这个代码是要被hack的

队友的正确做法

#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;

void add(int u,int v,int cap)
{
    //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];//当前弧优化
    int head=1,tail=1;
    q[1]=T;
    while(head<=tail)
    {
        int u=q[head++];
        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);
            add(u,N+v,1);
        }
        S=N+M+1,T=S+1,n=T;
        for(int i=1;i<=N;i++)
            add(S,i,L);
        for(int i=N+1;i<=N+M;i++)
            add(i,T,R);
        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{an} can be expressed as:

 

\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.an=0,2,23an1an2+n+1,n=0n=1n>1

 

Now there are two integers nn and mm. I'm a pretty girl. I want to find all b_1,b_2,b_3\cdots b_pb1,b2,b3bp that 1\leq b_i \leq n1bin and b_ibiis relatively-prime with the integer mm. And then calculate:

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

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 1500015000 ). Each case contains two integers nn and mm. 1\leq n,m \leq 10^81n,m108.

Output

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

Hint

In the all integers from 11 to 44, 11 and 33 is relatively-prime with the integer 44. So the answer is a_1+a_3=14a1+a3=14.

样例输入

4 4

样例输出

14

题目来源

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

函数是n*(n+1)

然后xjb容斥就行

#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}109 second. In the next 10^{-9}109 second, he built a data decoding device that decodes data encoded with his special binary coding rule to meaningful words.

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 00 and 11.

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 88-bit data there is 11 bit called parity bit, which should be '0' if there are odd number of '1's in the previous 88 bits and should be '1' if there are even number of '1's. If the parity bit does not meet the fact, then the whole 99 bits (including the parity bit) should be considered as invalid data and ignored. Data without parity bit is also considered as invalid data. Parity bits will be deleted after the parity check.

For example, consider the given data "101010101010101010101010", it should be divided into 33parts:"101010101","010101010" and "101010". For the first part, there are 44'1's in the first 88 bits, and parity bit is '1', so this part passed the check. For the second part, there are 4'1's and parity bit is '0', so this part failed the check. For the third part, it has less than 99 bits so it contains no parity bit, so this part also failed the check. The data after parity check is "10101010", which is the first 88 bits of first part.

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 NN pairs of corresponding relations from a bit string S_iSi to an ASCII code C_iCi, and the message length MM, they want to peek his privacy so they come to you to write a program that decodes messages that LATTICE receives.

Input

The first line an integer T\ (T<35)T (T<35)represents the number of test cases.

Every test case starts with one line containing two integers, M\ (0<M\leq100000)M (0<M100000), the number of original characters, and N\ (1\leq N \leq 256)N (1N256), then NN lines, every line contains an integer C_iCi, and a string S_i(0<|S_i|\leq 10)Si(0<Si10), means that S_iSi represents C_iCi, the ASCII code to a visible character and S_iSi only contains '0' or '1' and there are no two numbers ii and jj that S_iSi is prefix of S_jSj.

Then one line contains data that is going to be received in hexadecimal. (0<|data|<200000)(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 MM characters. Input guarantees that it will have no less than MM valid characters and all given ASCII codes represent visible characters.

Hint

Lattice's encoding rule for test case 22:

ASCII codecharacterlattice's code
4949 11 00010001
5050 22 0100101001
5151 33 011011

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 66 lines, each line contains 88 data bits and one parity bit

 
 
 
 
 
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 11 that cannot be formed by multiplying two smaller natural numbers.

Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all the numeric digits of NN must be either a prime number or 11.

For example, 1717 is a supreme number because 11, 77, 1717 are all prime numbers or 11, and 1919 is not, because 99 is not a prime number.

Now you are given an integer N\ (2 \leq N \leq 10^{100})N (2N10100), could you find the maximal supreme number that does not exceed NN?

Input

In the first line, there is an integer T\ (T \leq 100000)T (T100000) indicating the numbers of test cases.

In the following TT lines, there is an integer N\ (2 \leq N \leq 10^{100})N (2N10100).

Output

For each test case print "Case #x: y", in which xx is the order number of the test case and yy is the answer.

样例输入

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}d". "x\mathop{\rm d}yxdy" means that an yy-sided dice should be rolled xx times and the sum of the results is taken.

Formally, for any two integers x, yx,ysatisfying x \geq 0x0 and y \geq 1y1 , "x\mathop{\rm d}yxdy" means the sum of xx random integers in the range of [1, y][1,y]. It's obvious that either x < 0x<0 or y < 1y<1 makes the expression x\ {\rm d}\ yx d y illegal. For example: "2\mathop{\rm d}62d6" means that rolling a 66-sided dice 22 times. At this time, the result can be at least [1, 1] = 2[1,1]=2, and at most [6, 6] = 12[6,6]=12. The results of rolling can be used extensively in many aspects of the game. For example, an "1\mathop{\rm d}1001d100" can be used to determine whether an action with a percentage probability is successful, and a "3\mathop{\rm d}6+33d6+3 * 22" can be used to calculate the total damage when being attacked by 33 monsters simultaneously. In particular, the precedence of "\mathop{\rm d}d" is above "*". Since the operator "\mathop{\rm d}d" does not satisfy the associative law, it's necessary to make sure that "\mathop{\rm d}d" is right-associative.

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 3030 cases.

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 100100.

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][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;
            }
        }
    }
    return total;
}
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  暴力都不会的蒟蒻  阅读(...)  评论(...编辑  收藏