1. 程式人生 > >2017中國大學生程序設計競賽 - 網絡選拔賽

2017中國大學生程序設計競賽 - 網絡選拔賽

() follow include -- hint sid 不出 com sys

Friend-Graph

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


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 i技術分享 th row should contain n-i numbers, in which number a技術分享ij技術分享技術分享 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!
題目大意:判斷是否某個人有三個及三個以上的朋友或非朋友。 簽到題,思路:人數大於5的時候一定是bad team。 模擬就ok。
 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string
.h> 4 #include<algorithm> 5 using namespace std; 6 int num[3500]; 7 int main(){ 8 int T; 9 cin>>T; 10 while(T--){ 11 int n; 12 cin>>n; 13 int flag=0; 14 if(n>5) flag=1; 15 int x; 16 memset(num,0,sizeof(num)); 17 for(int i=1;i<n;i++){ 18 for(int j=1;j<=n-i;j++){ 19 scanf("%d",&x); 20 if(x==1){ 21 num[i]++; 22 num[i+j]++; 23 } 24 } 25 } 26 if(flag) cout<<"Bad Team!"<<endl; 27 else{ 28 for(int i=1;i<=n;i++){ 29 if(num[i]>=3||(n-1-num[i])>=3) flag=1; 30 } 31 if(flag) cout<<"Bad Team!"<<endl; 32 else cout<<"Great Team!"<<endl; 33 } 34 } 35 return 0; 36 }

A Secret

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


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.
思路:寫的時候覺得是kmp但是想了一下可能會超時。沒做,後來zll寫了超時,後面有人改了,還是用kmp AC了,666啊。 果然還是要寫了再說啊 套用一下大佬代碼:
 1 #include <iostream> 
 2 #include <algorithm> 
 3 #include <cstring> 
 4 #include <cstdio>
 5 #include <vector> 
 6 #include <queue> 
 7 #include <cstdlib> 
 8 #include <iomanip>
 9 #include <cmath>
10 #include <cassert>
11 #include <ctime> 
12 #include <map> 
13 #include <set> 
14 using namespace std; 
15 #define lowbit(x) (x&(-x)) 
16 #define max(x,y) (x>y?x:y) 
17 #define min(x,y) (x<y?x:y) 
18 #define MAX 100000000000000000 
19 #define MOD 1000000007
20 #define pi acos(-1.0) 
21 #define ei exp(1) 
22 #define PI 3.141592653589793238462
23 #define ios() ios::sync_with_stdio(false)
24 #define INF 1044266558
25 #define mem(a) (memset(a,0,sizeof(a)))
26 typedef long long ll;
27 const int maxn = 1e6+10;
28 #define next HKJournalist
29 ll next[maxn],i;
30 ll val[maxn],t,j,la,lb;
31 char sa[maxn], sb[maxn];
32 void get_next()
33 {
34     next[0]=-1;next[1]=0;
35     val[0]=0;val[1]=1;
36     for(i=1;i<lb;i++)
37     {
38         next[i+1]=0;
39         val[i+1]=i+1;
40         j=next[i];
41         while(j>=0)
42         {
43             if(sb[i]==sb[j])
44             {
45                 next[i+1]=j+1;
46                 val[i+1]+=val[j+1];
47                 val[i+1]%=MOD;
48                 break;
49             }
50             j=next[j];
51         }
52     }
53 }
54 ll find()
55 {
56     ll ans=0;
57     int k=0;
58     for(i=0;i<la;i++)
59     {
60         j=k;
61         for(k=0;j>=0;j=next[j])
62             if(sa[i]==sb[j])
63             {
64                 k=j+1;
65                 break;
66             }
67         ans = (ans+val[k])%MOD;
68     }
69     return ans;
70 }
71 
72 int main ()
73 {
74     scanf("%d", &t);
75     while(t--)
76     {
77         scanf("%s",sa);
78         scanf("%s",sb);
79         la=strlen(sa);
80         lb=strlen(sb);
81         reverse(sa,sa+la);
82         reverse(sb,sb+lb);
83         get_next();
84         printf("%lld\n",find());
85     }
86     return 0;
87 }

CaoHaha‘s staff

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2089 Accepted Submission(s): 818
Problem Description "You shall not pass!"
After shouted out that,the Force Staff appered in CaoHaha‘s hand.
As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help. Input The first line contains one integer T(T<=300).The number of toys.
Then T lines each contains one intetger S.The size of the toy(N<=1e9). Output Out put T integer in each line ,the least time CaoHaha can send the toy. Sample Input 5 1 2 3 4 5 Sample Output 4 4 6 6 7
題目大意:湊成一個面積為n的圖形至少幾筆能畫好,第五種情況折騰半天畫不出。 後來知道了還是找不到規律。。。 還是dalao的代碼: 附上一篇好理解的博客:http://blog.csdn.net/qq_36345036/article/details/77415176
 1 #include <bits/stdc++.h>
 2 #define ll long long int
 3 #define N 1000005
 4 using namespace std;
 5 int k[N];
 6 void fa(){
 7     memset(k,0,sizeof(k));
 8     k[0]=k[1]=0;
 9     for(int i=2;i<N;i++){
10         if(i%2==0){
11             k[i]=i/4*2+k[i-2];
12         }else{
13             k[i]=(i+1)/4+k[i-1]-1;
14         }
15     }
16 }
17 int main(){
18     int n;
19     fa();
20     scanf("%d",&n);
21     while(n--){
22         int x;
23         scanf("%d",&x);
24         for(int i=0;i<N;i++){
25             if(k[i]>=x){
26                 printf("%d\n",i);
27                 break;
28             }
29         }
30     }
31     return 0;
32 }

2017中國大學生程序設計競賽 - 網絡選拔賽