ACM-ICPC 2018 焦作赛区网络预赛
#include <bits/stdc++.h> using namespace std; char s[20]; int main() { int T; scanf("%d",&T); cin.ignore(); while(T--){ gets(s); int len = strlen(s); for(int i = 0;i < len;i++){ if(s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i]-'A' + 'a'; } if(s[0] == 'j' && s[1] == 'e' && s[2] == 's' && s[3] == 's' && s[4] == 'i' && s[5] == 'e' && len == 6) puts("Good guy!"); else puts("Dare you say that again?"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[1005][6][2]; long long v[1005]; char c[10]; int main() { int T; scanf("%d",&T); while(T--){ int n,k,m; scanf("%d%d%d",&n,&k,&m); for(int i = 0;i <= n;++i) for(int j = 0;j <= k;++j){ dp[i][j][0] = -0x3f3f3f3f3f3f3f3f; dp[i][j][1] = 0x3f3f3f3f3f3f3f3f; } dp[0][0][0] = dp[0][0][1] = m; for(int i = 1;i <= n;++i){ scanf("%lld",&v[i]); } for(int i = 1;i <= k;++i) cin >> c[i]; for(int i = 1;i <= n;++i){ dp[i][0][0] = dp[i][0][1] = dp[i-1][0][0]; for(int j = 1;j <= k && j <= i;++j){ if(c[j] == '+'){ dp[i][j][0] = max(dp[i-1][j-1][0] + v[i],dp[i-1][j][0]); dp[i][j][1] = min(dp[i-1][j-1][1] + v[i],dp[i-1][j][1]); } if(c[j] == '-'){ dp[i][j][0] = max(dp[i-1][j-1][0] - v[i],dp[i-1][j][0]); dp[i][j][1] = min(dp[i-1][j-1][1] - v[i],dp[i-1][j][1]); } if(c[j] == '*'){ dp[i][j][0] = max(dp[i-1][j-1][0] * v[i],dp[i-1][j][0]); dp[i][j][0] = max(dp[i-1][j-1][1] * v[i],dp[i][j][0]); dp[i][j][1] = min(dp[i-1][j-1][1] * v[i],dp[i-1][j][1]); dp[i][j][1] = min(dp[i-1][j-1][0] * v[i],dp[i][j][1]); } if(c[j] == '/'){ if(v[i] == 0){dp[i][j][0] = dp[i-1][j][0],dp[i][j][1] = dp[i-1][j][1];continue;} dp[i][j][0] = max(dp[i-1][j-1][0] / v[i],dp[i-1][j][0]); dp[i][j][0] = max(dp[i-1][j-1][1] / v[i],dp[i][j][0]); dp[i][j][1] = min(dp[i-1][j-1][0] / v[i],dp[i-1][j][1]); dp[i][j][1] = min(dp[i-1][j-1][1] / v[i],dp[i][j][1]); } } } long long ans = dp[n][k][0]; cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9+6; const int modd = 1e9+7; char num[100005]; ll poww(ll a,ll n){ ll ret = 1; while(n){ if(n&1){ ret = ret*a%modd; } n>>=1; a=a*a%modd; } return ret; } int main(){ int t;scanf("%d",&t); while(t--) { scanf("%s",num); if(num=="1"){ cout<<1<<endl;continue; } int len = strlen(num); if(num[len-1]>'0'){ num[len-1]--; } else{ num[len-1]='9'; int pos=len-2; while(num[pos]=='0'){ num[pos]='9'; pos--; } num[pos]--; } // cout<<num<<endl; int pp; for(int i=0;i<strlen(num);i++){ if(num[i]!=0){ pp=i;break; } } ll ans = 0; for(int i = pp; i < strlen(num); ++i){ ans = ans*10 + (num[i]-'0'); ans %= mod; } ll aa = poww(2,ans); aa%=modd; printf("%lld\n",aa); } return 0; }
H String and Times 后缀自动机裸题
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=200005; int K; struct SAM { int ch[maxn][26]; int pre[maxn],step[maxn]; int last,id; ll ans; int num[maxn]; void init() { ans=last=id=0; memset(ch[0],-1,sizeof(ch[0])); pre[0]=-1; step[0]=0; } void Insert(int c) { int p=last,np=++id; step[np]=step[p]+1; memset(ch[np],-1,sizeof(ch[np])); num[np]=0; while(p!=-1&&ch[p][c]==-1) ch[p][c]=np,p=pre[p]; if(p==-1) pre[np]=0; else { int q=ch[p][c]; if(step[q]!=step[p]+1) { int nq=++id; memcpy(ch[nq],ch[q],sizeof(ch[q])); num[nq]=num[q]; step[nq]=step[p]+1; pre[nq]=pre[q]; pre[np]=pre[q]=nq; while(p!=-1&&ch[p][c]==q) ch[p][c]=nq,p=pre[p]; } else pre[np]=q; } last=np; while(np!=-1&&num[np]<K) { num[np]++; if(num[np]>=K) ans+=step[np]-step[pre[np]]; np=pre[np]; } } }sam; char S[200001]; int main() { while(scanf("%s",S)!=EOF) { int a,b;cin>>a>>b; K = a; sam.init(); int N = strlen(S); for(int i=0;i<N;i++) sam.Insert(S[i]-'A'); ll res = sam.ans; K = b+1; sam.init(); for(int i=0;i<N;i++) sam.Insert(S[i]-'A'); ll re1 = sam.ans; //cout<<re1<<endl; res-=re1; cout<<res<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int a,b,c; while(cin>>a>>b>>c){ int sum = a*b*c; if(sum%2==1)cout<<"No"<<endl; else{ cout<<"Yes"<<endl; } } return 0; }
J Participate in E-sports 神奇的一血 !
//package acm; import java.awt.Container; import java.math.*; import java.util.*; import javax.swing.tree.TreeNode; import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID; public class Main { public static BigInteger bigSqrt(String s){ BigInteger remain=BigInteger.ZERO; BigInteger odd=BigInteger.ZERO; BigInteger ans=BigInteger.ZERO; // remain=BigInteger.ZERO; // odd=BigInteger.ZERO; // ans=BigInteger.ZERO; int group=0,k=0; if(s.length()%2==1) { group=s.charAt(0)-'0'; k=-1; } else { group=(s.charAt(0)-'0')*10+s.charAt(1)-'0'; k=0; } for(int j=0;j<(s.length()+1)/2;j++) { if(j!=0) group=(s.charAt(j*2+k)-'0')*10+s.charAt(j*2+k+1)-'0'; odd=BigInteger.valueOf(20).multiply(ans).add(BigInteger.ONE); remain=BigInteger.valueOf(100).multiply(remain).add(BigInteger.valueOf(group)); int count=0; while(remain.compareTo(odd)>=0) { count++; remain=remain.subtract(odd); odd=odd.add(BigInteger.valueOf(2)); } ans=ans.multiply(BigInteger.TEN).add(BigInteger.valueOf(count)); } return ans; } public static void main(String[] args) { Scanner cin=new Scanner(System.in); int t = cin.nextInt(); for(int i=0;i<t;i++) { BigInteger num = cin.nextBigInteger(); BigInteger ans = num.multiply(num.subtract(BigInteger.ONE)).divide(BigInteger.valueOf(2)); String sans = ans.toString(); String snum = num.toString(); BigInteger a1 = bigSqrt(snum); BigInteger a2 = bigSqrt(sans); int t1 = a1.multiply(a1).compareTo(num); int t2 = a2.multiply(a2).compareTo(ans); if(t1==0&&t2==0) { System.out.println("Arena of Valor"); } else if(t1==0 && t2!=0) { System.out.println("Hearth Stone"); } else if(t2==0 && t1!=0) { System.out.println("Clash Royale"); } else { System.out.println("League of Legends"); } } cin.close(); } }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long dp[10005]; int c[24],v[25]; int main() { int T; scanf("%d",&T); while(T--){ memset(dp,0,sizeof(dp)); dp[0] = 1; int n,q; scanf("%d%d",&n,&q); for(int i = 1;i <= n;++i){ scanf("%d%d",&v[i],&c[i]); c[i] = (1LL<<c[i]) - 1; } for(int i = 1;i <= n;++i){ int now = 1; while(c[i] - now > 0){ int vv = now * v[i]; for(int j = 10000;j >= vv;--j){ dp[j] += dp[j-vv]; dp[j] %= mod; } c[i] -= now; now <<= 1; } int vv = v[i] * c[i]; for(int j = 10000;j >= vv;--j) dp[j] += dp[j-vv],dp[j] %= mod; } int k; for(int i = 1;i <= q;++i){ scanf("%d",&k); printf("%lld\n",dp[k]); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define M 9 long long mod = 1e9 + 7; struct Mat{ long long e[M][M]; void init() {memset(e,0,sizeof(e));} }one; void init(){ one.init(); for(int i = 0;i < M;++i) one.e[i][i] = 1; } Mat operator * (Mat A,Mat B){ Mat C; C.init(); for(int k = 0;k < M;++k) for(int i = 0;i < M;++i){ if(A.e[i][k] == 0) continue; for(int j = 0;j < M;++j){ C.e[i][j] += A.e[i][k] * B.e[k][j]; C.e[i][j] %= mod; } } return C; } Mat operator ^ (Mat A,long long k){ Mat ret; ret = one; while(k){ if(k & 1) ret = ret * A; A = A * A; k >>= 1; } return ret; } int main() { init(); int T; scanf("%d",&T); Mat now; now.init(); now.e[0][3] = 1,now.e[0][6] = 1; now.e[1][0] = now.e[1][6] = 1; now.e[2][0] = now.e[2][6] = now.e[2][3] = 1; now.e[3][1] = now.e[3][4] = 1; now.e[4][1] = now.e[4][7] = 1; now.e[5][4] = now.e[5][7] = 1; now.e[6][2] = now.e[6][5] = now.e[6][8] = 1; now.e[7][2] = now.e[7][8] = 1; now.e[8][2] = now.e[8][5] = 1; while(T--){ long long n; scanf("%lld",&n);if(n == 1) {puts("3");continue;} Mat ans = now ^ (n-2); long long tot = 0; for(int i = 0;i < M;++i){ for(int j = 0;j < M;++j){ tot = (tot + ans.e[i][j]) % mod; } } cout << tot << endl; } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步