A:
#include <iostream> #include <cstdio> using namespace std; int main(){ int s,v1,v2,t1,t2; cin>>s>>v1>>v2>>t1>>t2; int ans1 =2* t1 + s * v1 ; int ans2 = 2*t2 + s * v2 ; if(ans1 == ans2) printf("Friendship\n"); else if(ans1 < ans2) printf("First\n"); else printf("Second\n"); return 0; } B: #include <iostream> #include <cstdio> #include <string.h> #include <algorithm> #define LL long long using namespace std; const int AX = 1e6; char a[AX]; int b[AX]; int main(){ int k ; scanf("%d",&k); scanf("%s",a); int len = strlen(a); int ans = 0; for( int i = 0 ; i < len ; i++ ){ ans += (a[i] - '0'); if( ans >= k ) {printf("0\n");return 0;} b[i] = a[i] - '0'; } sort(b,b+len); int temp = k - ans; for( int i = 0 ; i < len ; i++ ){ temp -= (9-b[i]); if( temp <= 0 ) {printf("%d\n",i+1); return 0;} } return 0; }C:
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm> #define LL long long using namespace std; int a[15][200][200]; int main(){ int n , q , c; scanf("%d%d%d",&n,&q,&c); int x,y,s; while( n-- ){ scanf("%d%d%d",&x,&y,&s); for( int i = 0 ; i <= 10 ; i++ ) a[i][x][y] += ( s + i )%( c + 1 ) ; } for( int k = 0 ; k <= 10 ; ++k){ for(int i = 1 ; i <= 100 ; i++ ){ for( int j = 1 ; j <=100 ; j++ ){ a[k][i][j] += a[k][i-1][j] + a[k][i][j-1] -a[k][i-1][j-1]; } } } int t, x1, y1, x2, y2; while( q -- ){ int ans = 0; scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2); t %= ( c + 1 ); ans = a[t][x2][y2] - a[t][x1-1][y2]-a[t][x2][y1-1]+a[t][x1-1][y1-1]; printf("%d\n",ans); } return 0; }D:dp[i][j] i到j是几阶回文
#include <bits/stdc++.h> using namespace std; const int AX = 5e3+666; char s[AX]; int dp[AX][AX]; int k[AX]; int main(){ scanf("%s",s+1); int len = strlen(s+1); memset( k , 0 , sizeof(k) ); for( int i = 1 ; i <= len ; i++ ){ dp[i][i] = 1; k[1]++ ; if( i < len && s[i] == s[i+1] ){ dp[i][i+1] = 2 ; k[2]++; k[1]++; } } for( int j = 3 ; j <= len; j++ ){ for( int i = 1 ; i + j - 1 <= len ; i++ ){ if( dp[i+1][i+j-2] && s[i+j-1] == s[i] ){ dp[i][i+j-1] = dp[i][i+j/2-1]+1; for( int kk = 1 ; kk <= dp[i][i+j-1] ;kk++ ) k[kk]++; } } } cout<<k[1]; for( int i = 2 ; i <= len ; i++ ){ printf(" %d",k[i]); } cout<<endl; return 0; }