菜鸡的2017CPPC网络赛
Friend-Graph
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6514 Accepted Submission(s): 1610
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.
The first line od each case should contain one integers n, representing the number of people of the team.(n≤3000)
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.
判断存不存在三元环,这个要拓扑排序跑一遍?emmm,wa
暴力判一下就好了,还得用bool
#include<stdio.h> #include<string.h> using namespace std; bool a[3001][3001]; int n; bool check() { int i,j,k; for(i=1; i<=n; i++) { for(j=i+1; j<=n; j++) { if(a[i][j]) for(k=1; k<=n; k++) { if(a[i][k]&&a[k][j]) { return 1; } } } } return 0; } int main() { int t,x,i,j,k,p,s; scanf("%d",&t); while(t--) { s=0; memset(a,false,sizeof(a)); scanf("%d",&n); for(i=1; i<=n; i++) { for(j=i+1; j<=n; j++) { scanf("%d",&x); if(x==1) a[i][j]=a[j][i]=true; } } if(check()) printf("Bad Team!\n"); else printf("Great Team!\n"); } return 0; }
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
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.
Then T lines each contains one intetger S.The size of the toy(N<=1e9).
就是在网格纸画面积为n需要的最小的棍子数,你的边可以是√2或者1,学姐莽了一发过了
我是躺赢的
#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; double f[100000]; int main() { __int64 t,n,i,j,p,q,l; for(i=4;;i+=2) { p=i/2; q=p/2; p=p-q; if(p<q) swap(p,q); f[i]=p*q*2; f[i+1]=f[i]+p-0.5; if(f[i]>=1000000000) break; l=i; //printf("%d..%d\n",i,f[i]); } //printf("%I64d\n",l); scanf("%I64d",&t); while(t--) { scanf("%I64d",&n); for(i=3;i<l;i++) if(f[i]>=n)break; printf("%I64d\n",i); } }
Palindrome Function
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 1141 Accepted Submission(s): 390
f(n,k)=k if n is a palindrome number under k-base.
Otherwise f(n,k)=1.
Now given you 4 integers L,R,l,r,you need to caluclate the mathematics expression ∑Ri=L∑rj=lf(i,j) .
When representing the k-base(k>10) number,we need to use A to represent 10,B to represent 11,C to repesent 12 and so on.The biggest number is Z(35),so we only discuss about the situation at most 36-base number.
In the following T lines,each line consists of 4 integers L,R,l,r.
(1≤T≤105,1≤L≤R≤109,2≤l≤r≤36)
据说是原题?可是我怎么会啊,这个还卡memset,要记忆化一下,学长过的,萌新瑟瑟发抖
#include<stdio.h> #include<string.h> #define ll __int64 int bits[100]; int dp[33][40][40]; int dfs(int len,int l,int r,bool flag,bool ok,int b) { if(r > l) return !flag || (flag && ok); if(!flag && ~dp[len][l][b+1]) return dp[len][l][b+1]; int end = flag ? bits[l] : b; int res = 0; for(int i=0;i<=end;i++) { if(l == len && i == 0) continue; bool g = ok; if(ok) g = bits[r] >= i; else g = bits[r] > i; res += dfs(len,l-1,r+1,flag&&(i==end),g,b); } return flag ? res : dp[len][l][b+1] = res; } int solve(int x,int b) { int tt = x; int cnt = 0; while(tt >0 ) { bits[++cnt] = tt % b; tt /= b; } int ret = 1; for(int i=cnt;i>=1;i--) ret += dfs(i,i,1,i==cnt,true,b-1); return ret; } int main() { int T; int C = 1; scanf("%d",&T); memset(dp,-1,sizeof(dp)); while(T--) { int l,r,m,n; __int64 ans=0; scanf("%d%d%d%d",&l,&r,&m,&n); for(int i=m;i<=n;i++){ int sum=r-l+1; int sum1=solve(r,i)-solve(l-1,i); ans+=sum-sum1+sum1*i; } printf("Case #%d: %I64d\n",C++,ans); } return 0; }
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.
InputInput 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.OutputFor 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(看毛片)要怎么魔改啊,懵懵懵,还不是自己不了解KMP
#include <bits/stdc++.h> using namespace std; const int N=1000005; char s[N],t[N]; int nex[N],sum[N]; const int MD=1e9+7; __int64 ans; __int64 getnum(__int64 x){ return (x+1)*x/2; } void pre(char *p) { int i,m,j; m=strlen(p); nex[0]=nex[1]=0; for(int i=1; i<m; i++) { j=nex[i]; while(j&&p[i]!=p[j])j=nex[j]; nex[i+1]=p[i]==p[j]?j+1:0; } } void kmp(char *t, char *p) { int j=0; int n=strlen(t); for(int i=0; i<n; i++) { while(j&&p[j]!=t[i]) { j=nex[j]; } if(p[j]==t[i]) { j++; ans=(ans+j)%MD; } ans=(ans+getnum(nex[j]))%MD; } } int main() { int T; scanf("%d",&T); getchar(); while(T--) { ans=0; scanf("%s",s); scanf("%s",t); reverse(s,s+strlen(s)); reverse(t,t+strlen(t)); pre(t); kmp(s,t); printf("%I64d\n",ans); } return 0; }
以下代码为昂老师写,这个思路感觉好
#include <bits/stdc++.h> using namespace std; const int N = 1000005; const int Q = 1e9 + 7; char s[N], t[N]; int n, m, f[N], cnt[N]; int main() { int T; scanf("%d", &T); while (T --) { scanf("%s%s", t, s); n = strlen(t); m = strlen(s); reverse(s, s + m); reverse(t, t + n); f[0] = f[1] = 0; for (int i = 1 ; i < m ; ++ i) { int j = f[i]; while (j && s[i] != s[j]) j = f[j]; f[i + 1] = s[i] == s[j] ? j + 1 : 0; } memset(cnt, 0, sizeof(int) * (m + 1)); for (int i = 0, j = 0 ; i < n ; ++ i) { while (j && t[i] != s[j]) j = f[j]; j += (t[i] == s[j]); ++ cnt[j]; } for (int i = m ; i > 0 ; -- i) { cnt[f[i]] += cnt[i]; } int res = 0; for (int i = 1 ; i <= m ; ++ i) { res += (long long)cnt[i] * i % Q; res %= Q; } cout << res << endl; } return 0; }
本文来自博客园,作者:暴力都不会的蒟蒻,转载请注明原文链接:https://www.cnblogs.com/BobHuang/p/7400397.html