zoukankan      html  css  js  c++  java
  • 周赛题解

    N!Again

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 23   Accepted Submission(s) : 10
    Problem Description
    WhereIsHeroFrom:             Zty, what are you doing ?
    Zty:                                     I want to calculate N!......
    WhereIsHeroFrom:             So easy! How big N is ?
    Zty:                                    1 <=N <=1000000000000000000000000000000000000000000000…
    WhereIsHeroFrom:             Oh! You must be crazy! Are you Fa Shao?
    Zty:                                     No. I haven's finished my saying. I just said I want to calculate N! mod 2009


    Hint : 0! = 1, N! = N*(N-1)!
     
    Input
    Each line will contain one integer N(0 <= N<=10^9). Process to end of file.
     
    Output
    For each case, output N! mod 2009
     
    Sample Input
    4 5
     
    Sample Output
    24 120
     
    题解:(a+b)%2009=a%2009+b%2009;而任一个数如果大于2009就可以写成a=(2009*x+b)再与另外一个数相乘有用的就是b也就是amod(%)2009;
    代码:
     1 #include<stdio.h> 
     2 #include<string.h>
     3 int main()
     4 {
     5     int temp,N;
     6     while(~scanf("%d",&N)){temp=1;
     7         for(int i=1;i<=N;i++){
     8             temp*=i;
     9             if(temp>=2009)temp%=2009;
    10             if(i>2009)break;
    11         }
    12         printf("%d
    ",temp);
    13     }
    14     return 0;
    15 } 
    View Code

    1sting

    Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 35   Accepted Submission(s) : 10
    Problem Description
    You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get.
     
    Input
    The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200.
     
    Output
    The output contain n lines, each line output the number of result you can get .
     
    Sample Input
    3 1 11 11111
     
    Sample Output
    1 2 8
     题解:大数斐波那契;
    代码:
     1 #include<stdio.h> 
     2 #include<string.h>
     3 #define MAX(x,y) x>y?x:y
     4 char a[201][1010]; 
     5 void bignum(char *x,char *y,int v){int c[1010],d[1010],z[1010];
     6     int t,t1,t2,i,j;
     7     memset(c,0,sizeof(c));
     8     memset(d,0,sizeof(d));
     9     memset(z,0,sizeof(z));
    10     t1=strlen(x);
    11     t2=strlen(y);
    12     t=MAX(t1,t2);
    13     for(i=t1-1,j=0;i>=0;i--,j++)c[j]=x[i]-'0';
    14     for(i=t2-1,j=0;i>=0;i--,j++)d[j]=y[i]-'0';
    15     for(i=0;i<t;++i){
    16         z[i]=c[i]+d[i]+z[i];
    17         if(z[i]>9)z[i+1]++,z[i]%=10;
    18         if(z[t])t++;
    19     }
    20     for(i=t-1,j=0;i>=0;i--,j++){
    21         a[v][j]=z[i]+'0';
    22     }
    23     a[v][j]='';
    24 }
    25 int main()
    26 {
    27     
    28     int n,m,i,j,l;
    29     char s[201];
    30     memset(a,0,sizeof(a));
    31     a[0][0]='0';
    32     a[1][0]='1';
    33     a[2][0]='2';
    34     //printf("%s %s %s
    ",a[0],a[1],a[2]);
    35     for(i=3;i<=200;i++)
    36     {
    37         bignum(a[i-1],a[i-2],i);
    38     }
    39     scanf("%d",&n);
    40     getchar();
    41     while(n--)
    42     {
    43         scanf("%s",s);
    44         l=strlen(s);
    45         printf("%s
    ",a[l]);
    46     }
    47     return 0;
    48 } 
    View Code

    Word Amalgamation

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
    Total Submission(s) : 5   Accepted Submission(s) : 3
    Problem Description
    In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to unscramble four words. Your task is to write a program that can unscramble words.
     
    Input
    The input contains four parts: 1) a dictionary, which consists of at least one and at most 100 words, one per line; 2) a line containing XXXXXX, which signals the end of the dictionary; 3) one or more scrambled 'words' that you must unscramble, each on a line by itself; and 4) another line containing XXXXXX, which signals the end of the file. All words, including both dictionary words and scrambled words, consist only of lowercase English letters and will be at least one and at most six characters long. (Note that the sentinel XXXXXX contains uppercase X's.) The dictionary is not necessarily in sorted order, but each word in the dictionary is unique.
     
    Output
    For each scrambled word in the input, output an alphabetical list of all dictionary words that can be formed by rearranging the letters in the scrambled word. Each word in this list must appear on a line by itself. If the list is empty (because no dictionary words can be formed), output the line "NOT A VALID WORD" instead. In either case, output a line containing six asterisks to signal the end of the list.
     
    Sample Input
    tarp given score refund only trap work earn course pepper part XXXXXX resco nfudre aptr sett oresuc XXXXXX
     
    Sample Output
    score ****** refund ****** part tarp trap ****** NOT A VALID WORD ****** course ******
     题解:查找,注意排序
    代码:
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 using namespace std;
     6 char m[10010][100];
     7 char temp[110],temp1[110];
     8 int cmp(const void *a,const void *b){
     9     if(strcmp((char *)a,(char *)b)>0)return 1;
    10     else return -1;
    11 }
    12 int t=0,c[110],p;
    13 int find(char *s){int x=strlen(s),y,flot=0;sort(s,s+x);p=0;
    14     for(int i=0;i<=t;++i){y=strlen(m[i]);
    15         strcpy(temp,m[i]);
    16         sort(temp,temp+y);
    17         if(!strcmp(temp,s))printf("%s
    ",m[i]),flot=1;
    18     }
    19     return flot;
    20 }
    21 int main(){
    22     int i;
    23     while(scanf("%s",m[t]),strcmp(m[t],"XXXXXX"))t++;
    24     qsort(m,t,sizeof(m[0]),cmp);
    25     while(scanf("%s",temp1),strcmp(temp1,"XXXXXX")){
    26         if(!find(temp1))puts("NOT A VALID WORD");
    27         puts("******");
    28     }
    29     return 0;
    30 }
    View Code

    叠筐

    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 52   Accepted Submission(s) : 11
    Problem Description
    需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。
     
    Input
    输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<N<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;< div>
     

    Output
    输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。
     

    Sample Input
    11 B A 5 @ W
     

    Sample Output
    AAAAAAAAA ABBBBBBBBBA ABAAAAAAABA ABABBBBBABA ABABAAABABA ABABABABABA ABABAAABABA ABABBBBBABA ABAAAAAAABA ABBBBBBBBBA AAAAAAAAA @@@ @WWW@ @W@W@ @WWW@ @@@
     题解:坑,注意两边磨损的都是空格;;;
    代码:
     1 /*1007题Input不全,后边内容为(n为满足0<n<80的奇整数),
     2 中心花色字符,外筐花色字符,后二者都为ASCII可见字符;*/
     3 #include<stdio.h>
     4 #include<string.h>
     5 char m[81][81];
     6 int main(){char a,b,c;
     7     int n,i,x,y,flot=0;
     8     while(~scanf("%d %c %c",&n,&a,&b)){i=1;x=y=0;
     9     if(flot)puts("");
    10     flot++;
    11     c=(n+1)/2%2?a:b;
    12     memset(m,0,sizeof(m));m[0][0]=c;
    13         while(i<n*n){
    14             while(m[y][x+1]==''&&x+1<n)m[y][++x]=c,i++;
    15             while(m[y+1][x]==''&&y+1<n)m[++y][x]=c,i++;
    16             while(m[y][x-1]==''&&x-1>=0)m[y][--x]=c,i++;
    17             while(m[y-1][x]==''&&y-1>=0)m[--y][x]=c,i++;
    18             c=a+b-c;
    19         }
    20         for(y=0;y<n;++y){
    21             for(x=0;x<n;x++){
    22                 if(n==1)m[0][0]=a;
    23                 else if(y==0)m[y][0]=' ',m[y][n-1]=' ';
    24                 else if(y==n-1)m[y][0]=' ',m[y][n-1]=' ';
    25                 m[y][n]='';
    26             }
    27         }
    28         if(n==1)printf("%c
    ",a);
    29         else for(y=0;y<n;++y)printf("%s
    ",m[y]);
    30     }
    31     return 0;
    32 }
    View Code

    I Love You Too

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 9   Accepted Submission(s) : 5
    Problem Description
    This is a true story. A man showed his love to a girl,but the girl didn't replied clearly ,just gave him a Morse Code:
    ****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/   He was so anxious that he asked for help in the Internet and after one day a girl named "Pianyi angel" found the secret of this code. She translate this code as this five steps:
    1.First translate the morse code to a number string:4194418141634192622374
    2.Second she cut two number as one group 41 94 41 81 41 63 41 92 62 23 74,according to standard Mobile phone can get this alphabet:GZGTGOGXNCS

    3.Third she change this alphabet according to the keyboard:QWERTYUIOPASDFGHJKLZXCVBNM = ABCDEFGHIJKLMNOPQRSTUVWXYZ
    So ,we can get OTOEOIOUYVL
    4.Fourth, divide this alphabet to two parts: OTOEOI and OUYVL, compose again.we will get OOTUOYEVOLI
    5.Finally,reverse this alphabet the answer will appear : I LOVE YOU TOO

    I guess you might worship Pianyi angel as me,so let's Orz her.
    Now,the task is translate the number strings.
     
    Input
    A number string each line(length <= 1000). I ensure all input are legal.
     
    Output
    An upper alphabet string.
     
    Sample Input
    4194418141634192622374 41944181416341926223
     
    Sample Output
    ILOVEYOUTOO VOYEUOOTIO
     题解:一遍ac,读懂题就好,不过想交个这样的女朋友也真累,要是我肯定看不出来;
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 char m[26]={'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'};
     4 char sj[11][5]={"","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
     5 char n[1010],temp1[1010],temp2[1010],temp3[1010];
     6 int t;
     7 void step1(char a,char b){
     8     temp1[t]=sj[a-'0'][b-'0'-1];
     9     for(int i=0;i<26;++i){
    10         if(m[i]==temp1[t])temp2[t]='A'+i;
    11     }
    12     t++;
    13 }
    14 void step2(){
    15     int v=strlen(temp2),i,j,k;
    16     memset(temp1,0,sizeof(temp1));
    17     //printf("%s
    ",temp2);
    18     for(i=0;i<(v+1)/2;++i)temp1[i]=temp2[i];
    19     for(i=0,j=(v+1)/2,k=0;j<v;++i,++j)temp3[k++]=temp1[i],temp3[k++]=temp2[j];
    20     if(v&1)temp3[k++]=temp2[(v+1)/2-1];
    21     //printf("%s
    ",temp3);
    22     for(i=0,j=k-1;i<k;i++,j--)n[i]=temp3[j];
    23     n[i]='';
    24 }
    25 int main(){
    26 char s[1010];
    27 while(~scanf("%s",s)){t=0;int x;
    28 memset(n,0,sizeof(n));
    29 memset(temp1,0,sizeof(temp1));
    30 memset(temp2,0,sizeof(temp2));
    31 memset(temp3,0,sizeof(temp3));
    32 x=strlen(s);
    33     for(int i=0;i<x;i+=2){
    34         step1(s[i],s[i+1]);
    35     }
    36     step2();
    37     printf("%s
    ",n);
    38 }
    39 return 0;}
    View Code
    1006题Input不全,后边内容是(0<n,m<=2000). The input is terminated when n=0 and m=0. 1007题Input不全,后边内容为(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;

    数塔

    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 14   Accepted Submission(s) : 11
    Problem Description
    在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:

    有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?

    已经告诉你了,这是个DP的题目,你能AC吗?
     

    Input
    输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 100),表示数塔的高度,接下来用N行数字表示数塔,其中第i行有个i个整数,且所有的整数均在区间[0,99]内。
     

    Output
    对于每个测试实例,输出可能得到的最大和,每个实例的输出占一行。
     

    Sample Input
    1 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
     题解:最简单的动态规划
    代码:
     1 #include<stdio.h>
     2 #define MAX(x,y) x>y?x:y 
     3 int dp[110][110];
     4 int main()
     5 {int x,y,N,C;
     6 scanf("%d",&C);
     7     while(C--){
     8         scanf("%d",&N);
     9         for(y=0;y<N;y++){
    10             for(x=0;x<=y;x++){
    11                 scanf("%d",&dp[x][y]);
    12             }
    13         }
    14         for(y=N-2;y>=0;y--){
    15             for(x=0;x<=y;x++){
    16                 dp[x][y]+=MAX(dp[x][y+1],dp[x+1][y+1]);
    17             }
    18         }
    19         printf("%d
    ",dp[0][0]);
    20     }
    21     return 0;
    22 } 
    View Code
     
     
  • 相关阅读:
    1065. [Nescafe19] 绿豆蛙的归宿(概率)
    SDOI 2016 Round1 Day2
    SDOI 2016 Round1 Day1
    Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
    串 2016Vijos省选集训 day3[AC自动机]
    java连接elastic search 9300
    maven安装,maven命令行使用
    eclipse/IDEA使用maven
    hadoop笔记 基础 归档
    tpot蜜罐平台搭建
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4676353.html
Copyright © 2011-2022 走看看