zoukankan      html  css  js  c++  java
  • 2017中国大学生程序设计竞赛

    Friend-Graph

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 3254    Accepted Submission(s): 523


    Problem Description
    It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn’t be any small groups in a good team.
    In a team with n members,if there are three or more members are not friends with each other or there are three or more members who are friends with each other. The team meeting the above conditions can be called a bad team.Otherwise,the team is a good team.
    A company is going to make an assessment of each team in this company. We have known the team with n members and all the friend relationship among these n individuals. Please judge whether it is a good team.
     
    Input
    The first line of the input gives the number of test cases T; T test cases follow.(T<=15)
    The first line od each case should contain one integers n, representing the number of people of the team.(n3000)

    Then there are n-1 rows. The ith row should contain n-i numbers, in which number aij represents the relationship between member i and member j+i. 0 means these two individuals are not friends. 1 means these two individuals are friends.
     
    Output
    Please output ”Great Team!” if this team is a good team, otherwise please output “Bad Team!”.
     
    Sample Input
    1 4 1 1 0 0 0 1
     
    Sample Output
    Great Team!
     题意:有一个表示朋友关系的图,如果有三个或超过三个的人彼此之间都不是朋友
    或者有三个或超过三个以上的朋友彼此之间都是朋友,那么这是一个Bad Team,否则是Great Team!
     当n>5时无论怎么连线都是 Bad Team,
    而n=1和n=2肯定是Great Team,所以需判断的范围就很小了,就剩下n为3,4,的情况
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define maxn 3007
     4 int ans[maxn];
     5 
     6 int main(){
     7     int T,n,t;
     8     int maxx,minn;
     9     scanf("%d",&T);
    10     while(T--){
    11     maxx=0,minn=maxn;
    12     memset(ans,0,sizeof(ans));
    13     scanf("%d",&n);
    14     for(int i=1;i<n;i++){
    15       for(int j=i+1;j<=n;j++){
    16         scanf("%d",&t);
    17         if(t==1){
    18         ans[i]++,ans[j]++; //记录图的度数
    19         maxx=max(maxx,ans[i]);  //保存最大度数
    20         maxx=max(maxx,ans[j]);
    21         }
    22       }
    23     } 
    24     for(int i=1;i<=n;i++)
    25         minn=min(minn,ans[i]);
    26     if(n>5) printf("Bad Team!
    ");
    27     else if(n<=2) printf("Great Team!
    ");
    28     else if(n==3){   //n为3
    29         if(minn==maxx&&(maxx=0||maxx==2))  //3个人都是朋友,3个人都不是朋友
    30             printf("Bad Team!
    ");
    31         else printf("Great Team!
    ");
    32     } 
    33     else {
    34         if(maxx<3&&minn>=n-3)    //n为4,画一下图就出来了
    35             printf("Great Team!
    ");
    36         else printf("Bad Team!
    ");
    37         }
    38     }
    39     return 0;
    40 }

    A Secret

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)
    Total Submission(s): 195    Accepted Submission(s): 83


    Problem Description
    Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell:
      Suffix(S2,i) = S2[i...len].Ni is the times that Suffix(S2,i) occurs in S1 and Li is the length of Suffix(S2,i).Then the secret is the sum of the product of Ni and Li.
      Now SF wants you to help him find the secret.The answer may be very large, so the answer should mod 1000000007.
     


    Input
    Input contains multiple cases.
      The first line contains an integer T,the number of cases.Then following T cases.
      Each test case contains two lines.The first line contains a string S1.The second line contains a string S2.
      1<=T<=10.1<=|S1|,|S2|<=1e6.S1 and S2 only consist of lowercase ,uppercase letter.
     


    Output
    For each test case,output a single line containing a integer,the answer of test case.
      The answer may be very large, so the answer should mod 1e9+7.
     


    Sample Input
    2
    aaaaa
    aa
    abababab
    aba
     
    Sample Output
      13
      19
    Hint
    case 2:
    Suffix(S2,1) = "aba",
    Suffix(S2,2) = "ba",
    Suffix(S2,3) = "a".
    N1 = 3,
    N2 = 3,
    N3 = 4.
    L1 = 3,
    L2 = 2,
    L3 = 1.

    ans = (3*3+3*2+4*1)%1000000007.

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <string.h>
     4 using namespace std;
     5 #define ll long long 
     6 const int maxn=1e6+5;
     7 int n,m,Next[maxn];
     8 char s[maxn],t[maxn];
     9 ll id[maxn];
    10 const int mod=1e9+7;
    11 void getNext(){
    12     int i=0,j=-1;
    13     Next[0]=-1;
    14         while(i<m){
    15         if(j==-1||t[i]==t[j])
    16             Next[++i]=++j;
    17         else j=Next[j];
    18         }
    19 }
    20 void kmp(){  
    21     int i=0,j=0;
    22     while(i<n){ 
    23     if(j==-1||s[i]==t[j])
    24         ++i,++j;
    25     else j=Next[j]; 
    26     id[j]++; 
    27     if(j==m) j=Next[j]; 
    28     } 
    29 }
    30 int main(){ 
    31     int T;
    32     scanf("%d",&T);
    33     while(T--){
    34     memset(id,0,sizeof(id));
    35     scanf("%s%s",s,t);
    36     n=strlen(s),m=strlen(t);
    37     for(int i=0;i<=(n-1)>>1;i++)
    38         swap(s[i],s[n-1-i]);
    39     for(int i=0;i<=(m-1)>>1;i++)
    40         swap(t[i],t[m-1-i]);
    41     getNext();
    42     kmp();
    43     ll ans=0;
    44     for(int i=m;i>0;--i){
    45     id[Next[i]]+=id[i];
    46     ans=(ans+id[i]*i)%mod;
    47         }
    48     printf("%lld
    ",ans);
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    Oracle必须要启动的服务
    Oracle_Kill_Session_终极篇
    oracle 修改用户密码
    ORA-01000-超出打开游标的最大数(解决及原因)
    ORA-00600 内部错误代码, 参数 [19004]
    done 多米诺pizza oa 考了spring boot编程
    ebay mettle印度网站oa 切换屏幕就报警
    done摩根史丹利m&t oa
    done peapod 不被太尊重的不面了
    有一点题 virtusa 空口说代码的电面
  • 原文地址:https://www.cnblogs.com/z-712/p/7402373.html
Copyright © 2011-2022 走看看