周末训练笔记+2017 ACM/ICPC Asia Regional Qingdao+Xian Online(9.17)

来源:互联网 发布:mac mockup软件 编辑:程序博客网 时间:2024/05/21 19:32

昨天的西安赛区的就不说啥了,基本算是零鸭蛋,唯一过得一个“脑洞题”还是道听途说,最有戏的第二题,硬币概率那个,手算会算,代码敲出来,一直就达不到预期的精度,后来看题解,算法也有点问题,尴尬;青岛这场,前半程做的挺快,后半程就一直tle顺便看学长表演了,我们这边服务器崩溃了交了不知道结果,盲交,字符串的那个题,坑的我们不轻啊,调了半天的第一题结束后才知道wa了。

1001Apple

大体就是给出三个点的坐标,然后在给你一个点,问你这个点在不在前三个点组成的三角形确立的外接圆内

1003The Dominator of Strings

主导字符串就是其他串都是这个主导串的子串

给你n个字符串,求这个主导串

思路是很清晰的,主导最长的串,然后暴力查找解决,tle,我还一直以为是输入的问题,修改完输入还是tle,当时没找到更好的优化方法,到最后也没过

1008 Chinese Zodiac

生肖差几年

1011A Cubic number and A Cubic Number

n组询问,给你一个素数看看是否是两个数的立方之差

暴力解决可能会行不通,这个很快就找出了公式,每个数的立方差3*n*(n+1)+1   接下来暴力查找就行了

 B. Coin

有一个不均匀的硬币,给出抛到正面的概率,一共k次,问你抛到正面向上的次数是偶数次的概率是多少mod1e+9+7  0也算是偶数

样例1:  2 1 1       0次     1/2*mod

样例2:  3 1 2        0+2次       (2/3*2/3+1/3+1/3)*mod

C. Sum

给出一个x,求k*x的每位数字相加可以被233整除,

脑洞最大的一个题,竟然还有通解,还有好几种,

1:直接输出233个9   

3:直接输出1000000233次最后再加个1

 

Apple

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Apple is Taotao's favourite fruit. In his backyard, there are three apple trees with coordinates (x1,y1)(x2,y2), and (x3,y3). Now Taotao is planning to plant a new one, but he is not willing to take these trees too close. He believes that the new apple tree should be outside the circle which the three apple trees that already exist is on. Taotao picked a potential position (x,y) of the new tree. Could you tell him if it is outside the circle or not?
 

Input
The first line contains an integer T, indicating that there are T(T30) cases.
In the first line of each case, there are eight integers x1,y1,x2,y2,x3,y3,x,y, as described above.
The absolute values of integers in input are less than or equal to 1,000,000,000,000.
It is guaranteed that, any three of the four positions do not lie on a straight line.
 

Output
For each case, output "Accepted" if the position is outside the circle, or "Rejected" if the position is on or inside the circle.
 

Sample Input
3-2 0 0 -2 2 0 2 -2-2 0 0 -2 2 0 0 2-2 0 0 -2 2 0 1 1
 

Sample Output
AcceptedRejectedRejected
package 青岛网络赛;import java.util.Scanner;import java.math.BigDecimal;import java.math.BigInteger;public class Main {    public static void main(String []args)    {    Scanner sc=new Scanner(System.in);    int t;    double s;    t=sc.nextInt();    while(t>0)    {    s=sc.nextDouble();    BigDecimal x1 = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal y1 = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal x2 = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal y2 = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal x3 = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal y3 = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal x = new BigDecimal(Double.toString(s));    s=sc.nextDouble();    BigDecimal y = new BigDecimal(Double.toString(s));    BigDecimal i = new BigDecimal(Double.toString(2.0));    BigDecimal a=(x1.subtract(x2));    BigDecimal b=(y1.subtract(y2));    BigDecimal c=(x1.subtract(x3));    BigDecimal d=(y1.subtract(y3));    BigDecimal a1 = x1.multiply(x1);    BigDecimal b1 = y1.multiply(y1);    BigDecimal a2 = x2.multiply(x2);    BigDecimal b2 = y2.multiply(y2);    BigDecimal a3 = x3.multiply(x3);    BigDecimal b3 = y3.multiply(y3);    BigDecimal e = ((a1.subtract(a2)).add (b1.subtract(b2))).divide(i);    BigDecimal f = ((a1.subtract(a3)).add (b1.subtract(b3))).divide(i);    System.out.println(e+" "+f);    BigDecimal det=(b.multiply(c)).subtract(a.multiply(d));    System.out.println(det);    BigDecimal x0=((d.multiply(e)).subtract(b.multiply(f))).divide(det);    BigDecimal y0=((a.multiply(f)).subtract(c.multiply(e))).divide(det);    BigDecimal r1=(((x1.add(x0)).multiply(x1.add(x0))).add((y1.add(y0)).multiply(y1.add(y0))));    BigDecimal r2=(((x.add(x0)).multiply(x.add(x0))).add((y.add(y0)).multiply(y.add(y0))));    if(r2.compareTo(r1)==1)    System.out.println("Accepted");    else System.out.println("Rejected");    t--;    }         }}


Chinese Zodiac

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
The Chinese Zodiac, known as Sheng Xiao, is based on a twelve-year cycle, each year in the cycle related to an animal sign. These signs are the rat, ox, tiger, rabbit, dragon, snake, horse, sheep, monkey, rooster, dog and pig.
Victoria is married to a younger man, but no one knows the real age difference between the couple. The good news is that she told us their Chinese Zodiac signs. Their years of birth in luner calendar is not the same. Here we can guess a very rough estimate of the minimum age difference between them.
If, for instance, the signs of Victoria and her husband are ox and rabbit respectively, the estimate should be 2 years. But if the signs of the couple is the same, the answer should be 12 years.
 

Input
The first line of input contains an integer T (1T1000) indicating the number of test cases.
For each test case a line of two strings describes the signs of Victoria and her husband.
 

Output
For each test case output an integer in a line.
 

Sample Input
3ox roosterrooster oxdragon dragon
 

Sample Output
8412
#include<iostream>#include<cstdio>#include<cstring>#include<string.h>#include<stdio.h>using namespace std;int main()    {    char x[12][10]={"rat","ox","tiger","rabbit","dragon","snake","horse","sheep","monkey","rooster","dog","pig"};    char a[10],b[10];    int i,s1,s2,t;    cin>>t;    while(t--)        {        cin>>a>>b;        if(strcmp(a,b)==0)            {            cout<<12<<endl;            continue;            }        for(i=0;i<12;i++)            {            if(strcmp(a,x[i])==0)                s1=i;            if(strcmp(b,x[i])==0)                s2=i;            }        if(s1<s2)            cout<<(s1-s2)*-1<<endl;        else            cout<<12-s1+s2<<endl;        }    return 0;    }

A Cubic number and A Cubic Number

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
A cubic number is the result of using a whole number in a multiplication three times. For example, 3×3×3=27 so 27 is a cubic number. The first few cubic numbers are 1,8,27,64 and 125. Given an prime number p. Check that if p is a difference of two cubic numbers.
 

Input
The first of input contains an integer T (1T100) which is the total number of test cases.
For each test case, a line contains a prime number p (2p1012).
 

Output
For each test case, output 'YES' if given p is a difference of two cubic numbers, or 'NO' if not.
 

Sample Input
102357111317192329
 

Sample Output
NONONOYESNONONOYESNONO
#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>using namespace std;/*long long prime[1000000];int vis[1000000];void find(){    int k=0;    vis[0]=0;    vis[1]=0;    for(int i=2;i<=10000;i++)    {        if(vis[i]==1)        {            prime[k]=i;            k++;            for(int j=i;j<=10000;j+=i)                vis[j]=0;        }    }}*//*void find3(){    long long temp=1;    for(int i=2;i<100000;i++)    {        for()        map[k]=i*i*i-temp;        temp=i*i*i;        k++;        }    }*/int main(){    //for(int i=0;i<1000000;i++)    //vis[i]=1;    //find();    //for(int i=0;i<20;i++)    //{       // cout<<prime[i]<<endl;        //}    //find3();    int t;    cin>>t;    long long x;    while(t--)    {        cin>>x;        int flag=0;        for(long long  i=1;i<10000000;i++)        {            if((long long )(3*i*(i+1)+1)==x)            {                flag=1;                break;            }        }        if(flag==1)        cout<<"YES"<<endl;        else cout<<"NO"<<endl;    }    return 0;    }

The Dominator of Strings

Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Here you have a set of strings. A dominator is a string of the set dominating all strings else. The string S is dominated by T if S is a substring of T.
 

Input
The input contains several test cases and the first line provides the total number of cases.
For each test case, the first line contains an integer N indicating the size of the set.
Each of the following N lines describes a string of the set in lowercase.
The total length of strings in each case has the limit of 100000.
The limit is 30MB for the input file.
 

Output
For each test case, output a dominator if exist, or No if not.
 

Sample Input
310youbetterworsericherpoorersicknesshealthdeathfaithfulnessyoubemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulness5abccdeabcdeabcdebcde3aaaaaaaaabaaaac
 

Sample Output
youbemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulnessabcdeNo

又学了一招
因为不知道Java里怎么快速去查找字符串里是否有另一个子字符串
c++种stl种的find()  我还以为肯定可以了   
import java.io.*;public class Main {    static String str[]=new String[100010];    public static void main(String[] args) throws IOException {        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));        String t=bf.readLine();        int T=Integer.parseInt(t);        while(T>0){            String nr=bf.readLine();            int n;            n=Integer.parseInt(nr);            String fstr="";            for(int i=0;i<n;i++){                str[i]=bf.readLine();                if(str[i].length()>fstr.length()) fstr=str[i];                }            int flag=1;            for(int i=0;i<n;i++){                if(!fstr.contains(str[i])){                    flag=0;break;                }            }            if(flag==1) System.out.println(fstr);            else System.out.println("No");            T--;        }    }}
#include<iostream>#include<stdio.h>#include<string.h>#include<string>using namespace std;string map[100010];int n;int ma=0;int temp=0;void init(){    string s;    scanf("%d",&n);    for(int i=0;i<n;i++)    {        //cin>>map[i];        cin>>map[i];        //len[i]=map[i].size();        if(map[i].size()>ma)        {            ma=map[i].size();            temp=i;            }    }}int judge(string s1,string s2){    string::size_type idx;    idx=s1.find(s2);    if(idx == string::npos )        return 0;    else        return 1;    }/*int judge(string s1,string s2){    int sum=0;    for(int i=0;i<s1.size();i++)    {        sum=0;        if(s2[0]==s1[i])        {            for(int j=1;j<s2.size();j++)            {                if(s2[j]==s1[i+j])                {                    //cout<<s2[j]<<" "<<s1[i+j]<<endl;                    sum++;                }                }               // cout<<sum+1<<endl;                if(sum+1==s2.size())                return 1;            }        }    return 0;    }*/void solve(){    for(int i=0;i<n;i++)    {        if(judge(map[temp],map[i])==0)        {            cout<<"NO"<<endl;            return ;            }        }    cout<<map[temp]<<endl;    }int main(){    int t;    //string s1="youbemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulness";    //string s2="bemuylhlhlh";    //cout<<judge(s1,s2)<<endl;    scanf("%d",&t);    while(t--)    {        ma=0;        temp=0;        //memset(map,0,sizeof(map));        init();        solve();        }    return 0;    }

C. Sum

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.

样例输入

11

样例输出

89999999999999999999999999

#include<iostream>#include<stdio.h>using namespace std;int main(){    int T;    cin >> T;    while (T--){        int x;        cin >> x;    for(int i=0;i<232;i++)    {        cout << 1000000;        }        cout << 1 << endl;    }    return 0;    }


 B. Coin

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(pq21).

The question is, when Bob tosses the coin kk times, 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(1\le 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.

样例输入

22 1 13 1 2

样例输出

500000004555555560

[1+(p-2q)^n*(p^n)^(mod-2)%mod]*2^(mod-2)%mod;

#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
const long long mod=1000000007;
long long pow(long long p,  long long n) 
{
    long long s=1;
    while(n)
    {
        if(n&1)
        s=(s*p)%mod;
        n>>=1;
        p=(p*p)%mod;
    }
    return s;
}
int main()
{
    int t;
    long long p,q,k;
    cin>>t;
    while(t--) 
    {
        scanf("%lld%lld%lld",&p,&q,&k);
        //cout<<pow(p-2*q,k)<<endl;
        //cout<<pow(2,3)<<endl;
        long long a=(((1+pow(p-2*q,k)*pow(pow(p,k),mod-2))%mod)*pow(2,mod-2))%mod;
        cout<<a<<endl;
    }
    return 0;
}

原创粉丝点击