2017 ACM-ICPC 亚洲区(西安赛区)网络赛

这个西安赛区大概是我们学校打得最好的一次了,因为数学题多,而且嘛,那个I竟然就是暴力,恭喜我们学校分了个机会

    1. Coin

问答

  •  23.46%
  •  1000ms
  •  32768K

Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is frac{q}{p}(frac{q}{p} le frac{1}{2})pq​​(pq​​21​​).

The question is, when Bob tosses the coin kktimes, what's the probability that the frequency of the coin facing up is even number.

If the answer is frac{X}{Y}YX​​, because the answer could be extremely large, you only need to print (X * Y^{-1}) mod (10^9+7)(XY1​​)mod(109​​+7).

Input Format

First line an integer TT, indicates the number of test cases (T le 100T100).

Then Each line has 33 integer p,q,k(1le p,q,k le 10^7)p,q,k(1p,q,k107​​) indicates the i-th test case.

Output Format

For each test case, print an integer in a single line indicates the answer.

样例输入

2
2 1 1
3 1 2

样例输出

500000004
555555560

题目来源

2017 ACM-ICPC 亚洲区(西安赛区)网络赛

这个可以推到一个公式

(P^n+(p-2q)^n)/(2*p^n)

这个要得到这个数要求逆元什么的,因为直接除会造成误差

当时写的那么脑残么,奇质数可以直接求

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MD=1e9+7;
ll po(ll a, ll b)
{
    ll ans=1;
    for(;b;a=a*a%MD,b>>=1)if(b&1)ans=ans*a%MD;
    return ans;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ll p,q,k;
        scanf("%lld%lld%lld",&p,&q,&k);
        printf("%lld
",(po(p,k)+po(p-2*q,k))*po(2*po(p,k),MD-2)%MD);
    }
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int MD=1e9+7;
typedef long long LL;
LL po(LL a, LL b)
{
    LL ans=1;
    while(b){
        if(b&1)
        ans=ans*a%MD;
        b=b/2;
        a=a*a%MD;
    }
    return ans;
}
LL la(LL a,LL b,LL &x,LL &y)
{
    LL d;
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    d=la(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        LL p,q,k;
        scanf("%lld%lld%lld",&p,&q,&k);
        LL x,y;
        la(2*po(p,k),MD,x,y);
        x=(x%MD+MD)%MD;
        printf("%lld
",(po(p,k)+po(p-2*q,k))*x%MD);
    }
    return 0;
}
    1. Sum

问答

  •  40.09%
  •  1000ms
  •  32768K

Define the function S(x)S(x) for xx is a positive integer. S(x)S(x) equals to the sum of all digit of the decimal expression of xx. Please find a positive integer kk that S(k*x)\%233=0S(kx)%233=0.

Input Format

First line an integer TT, indicates the number of test cases (T le 100T100). Then Each line has a single integer x(1 le x le 1000000)x(1x1000000)indicates i-th test case.

Output Format

For each test case, print an integer in a single line indicates the answer. The length of the answer should not exceed 20002000. If there are more than one answer, output anyone is ok.

样例输入

1
1

样例输出

89999999999999999999999999

这个C的构造嘛,其实还是比较巧妙的。有输出233个9或1e6过的,1e6这个比较好想,因为每一位都得到贡献都相同,所以233次一定是233的倍数

#include<stdio.h>
int main()
{
    int t,n,a=(int)1e6;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=233;i++)
        printf("%d",a);
        puts("");
    }
} 
    1. Maximum Flow

问答

  •  19.64%
  •  1000ms
  •  32768K

Given a directed graph with nnn nodes, labeled 0,1,⋯,n−10,1, cdots, n-10,1,,n1.

For each <i,j><i, j><i,j> satisfies 0≤i<j<n0 le i < j < n0i<j<n, there exists an edge from the i-th node to the j-th node, the capacity of which is iii xor jjj.

Find the maximum flow network from the 0-th node to the (n-1)-th node, modulo 100000000710000000071000000007.

Input Format

Multiple test cases (no more than 100001000010000).

In each test case, one integer in a line denotes n(2≤n≤1018)n(2 le n le 10^{18})n(2n1018​​).

Output Format

Output the maximum flow modulo 100000000710000000071000000007for each test case.

样例输入

2

样例输出

1

题目来源

2017 ACM-ICPC 亚洲区(西安赛区)网络赛

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define LL long long
#define mod 1000000007
using namespace std;
int main()
{
    LL a[100]={0},b[100]={0},c[100]={0},d[100],i;
    a[1]=1;b[1]=1;
    for(i=2;i<62;i++){
        a[i]=a[i-1]*2;//每行个数 
        b[i]=b[i-1]+a[i];//总个数 
        b[i]%=mod;
    }
    d[1]=1;
    for(i=2;i<62;i++){
        d[i]=(d[i-1]*4)%mod;
    }
    c[1]=1;
    for(i=2;i<62;i++){
        c[i]=((2*c[i-1])%mod+(d[i]-d[i-1]+mod)%mod+mod)%mod;//每组的和 
    }
    LL n,m;
    while(~scanf("%lld",&n)){
        LL k=0,kk=n-1;
        for(i=1;i<=60;i++){
            if(a[i]<kk){
                kk-=a[i];
            }else 
                break;
        }
        k=i;
        LL sum=0;
        for(i=1;i<k;i++)
            sum=(sum+c[i])%mod;
        m=n;
        n-=a[k];
        //printf("k = %lld %lld %lld
",k,sum,n);
        for(i=k-1;i>=1;i--){
            //printf("%lld - %lld
",n,a[i]);
            if(n>a[i]){
                sum=(sum+c[i])%mod;
                n-=a[i];
            }
            //if(n<=0)break;
        }
        printf("%lld
",(sum+m-1+mod)%mod); 
    }
} 
    1. Barty's Computer

问答

  •  22.95%
  •  4000ms
  •  524288K

Barty have a computer, it can do these two things.

  1. Add a new string to its memory, the length of this string is even.

  2. For given 444 strings a,b,c,da,b,c,da,b,c,d, find out how many strings that can be product by a+s1+b+c+s2+da+s1+b+c+s2+da+s1+b+c+s2+d, and ∣a∣+∣s1∣+∣b∣=∣c∣+∣s2∣+∣d∣|a| + |s1| + |b| = |c| + |s2| + |d|a+s1+b=c+s2+d∣. ∣s∣|s|s∣means the length of string sss, s1s1s1 and s2s2s2 can be any string, including "".

Please help your computer to do these things.

Input Format

Test cases begins with T(T≤5)T(T le 5)T(T5).

Then TTT test cases follows.

Each test case begins with an integer Q(Q≤30000)Q(Q le 30000)Q(Q30000).

Then QQQ lines,

1 s: add a new string sss to its memory.

2 a b c d: find how many strings satisfying the requirement above.

∑∣s∣+∣a∣+∣b∣+∣c∣+∣d∣≤2000000sum |s| + |a| + |b| + |c| + |d| le 2000000s+a+b+c+d2000000.

Output Format

For type 222 query. Output the answer in one line.

样例输入

1
10
1 abcqaq
1 abcabcqaqqaq
2 ab bc qa aq
2 a c q q
1 abcabcqaqqwq
2 ab bc qa aq
2 a c q q
1 abcq
2 a c q q
2 a b c q

样例输出

1
2
1
3
3
1

题目来源

2017 ACM-ICPC 亚洲区(西安赛区)网络赛

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
char str[N], a[N], b[N], c[N], d[N];
const LL mod = 1e9+7;
const LL MD = 1313;
LL *has[N], pos[N];
int xlen[N];

int main()
{
    pos[0]=1;
    for(int i=1;i<N;i++) pos[i]=pos[i-1]*MD%mod;
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int h=0;
        while(n--)
        {
            int xx;
            scanf("%d", &xx);
            if(xx==1)
            {
                scanf("%s",str+1);
                int l=strlen(str+1);
                xlen[h]=l;
                has[h]=new LL[l+3];
                has[h][0]=0;
                for(int i=1;i<=l;i++)
                    has[h][i]=(has[h][i-1]*MD%mod+(str[i]-'a'+1))%mod;
                h++;
            }
            else
            {
                scanf("%s %s %s %s",a+1,b+1,c+1,d+1);
                int l1=strlen(a+1),l2=strlen(b+1),l3=strlen(c+1),l4=strlen(d+1);
                int sum=l1+l2+l3+l4, cnt=0;
                LL ans1=0, ans2=0, ans3=0, ans4=0;
                for(int j=1; j<=l1; j++) ans1=(ans1*MD%mod+(a[j]-'a'+1))%mod;
                for(int j=1; j<=l2; j++) ans2=(ans2*MD%mod+(b[j]-'a'+1))%mod;
                for(int j=1; j<=l3; j++) ans3=(ans3*MD%mod+(c[j]-'a'+1))%mod;
                for(int j=1; j<=l4; j++) ans4=(ans4*MD%mod+(d[j]-'a'+1))%mod;

                for(int i=0;i<h;i++)
                {
                    if((xlen[i]&1)||l1+l2>xlen[i]/2||l3+l4>xlen[i]/2) continue;
                    int cx=xlen[i]/2;
                    LL x=has[i][l1];
                    if(x!=ans1) continue;
                    x=(has[i][cx]-has[i][cx-l2]*pos[l2]%mod+mod)%mod;
                    if(x!=ans2) continue;
                    x=(has[i][cx+l3]-has[i][cx]*pos[l3]%mod+mod)%mod;
                    if(x!=ans3) continue;
                    x=(has[i][2*cx]-has[i][2*cx-l4]*pos[l4]%mod+mod)%mod;
                    if(x!=ans4) continue;
                    cnt++;
                }
                printf("%d
",cnt);
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/BobHuang/p/7568192.html