a.cc
#include <stdio.h> #include <iostream> using namespace std; int main() { long long xa, xb, xc; long long ya, yb, yc; long long i, j; cin>> xa>> ya>> xb>> yb>> xc>> yc; if((yb-ya)*(xc-xb) == (yc-yb)*(xb-xa)) { printf("TOWARDS\n"); return 0; } if(xb > xa && yb > ya) { if(xc > xb) { printf("RIGHT\n"); return 0; } else { printf("LEFT\n"); return 0; } } else if(xb < xa && yb < ya) { if(xc < xb) { printf("RIGHT\n"); return 0; } else { printf("LEFT\n"); return 0; } } else if(xb > xa && yb < ya) { if(xc > xb) { printf("LEFT\n"); return 0; } else { printf("RIGHT\n"); return 0; } } else if(xb < xa && yb > ya) { if(xc < xb) { printf("LEFT\n"); return 0; } else { printf("RIGHT\n"); return 0; } } if(xc == xb) { if((xb-xa)*(yc-yb) < 0) { printf("RIGHT\n"); return 0; } else { printf("LEFT\n"); return 0; } } else if(yc == yb) { if((xc-xb)*(yb-ya) > 0) { printf("RIGHT\n"); return 0; } else { printf("LEFT\n"); return 0; } } return 0; }
#include <stdio.h> #include <iostream> using namespace std; #define LEN 100001 long long a[LEN], b[LEN]; int main() { long long n, m; long long i, j; long long tmp, ansa, ansb; cin>> n; for(i = 1; i <= n; i++) { cin>> tmp; a[tmp] = i; } ansa = ansb = 0; cin>> m; for(i = 1; i <= m; i++) { cin>> tmp; ansa += a[tmp]; ansb += (n-a[tmp]+1); } cout<< ansa<< " "<< ansb<< endl; return 0; }
看了ACMonster大神的第一题代码,学习了:
a.cc
//program 227-A #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int main() { long long X0,Y0,X1,Y1,X2,Y2; cin>>X0>>Y0>>X1>>Y1>>X2>>Y2; long long Ans=(X0*Y1+X1*Y2+X2*Y0)-(Y0*X1+Y1*X2+Y2*X0); if(Ans<0)printf("RIGHT\n"); if(Ans==0)printf("TOWARDS\n"); if(Ans>0)printf("LEFT\n"); return 0; }
第四题看了别人的代码后AC了,伤啊,小错误不断:
d.cc
#include <stdio.h> #include <algorithm> #include <iostream> #include <string.h> using namespace std; #define LEN 100010 int num[LEN]; long long res[LEN]; long long sum[LEN]; int cmp(const void* a, const void* b) { return *(long long*)b - *(long long*)a; } int main() { long long n, q; int i, j; long long ans, k; while(cin>> n) { memset(res, 0, sizeof(res)); memset(sum, 0, sizeof(sum)); for(i = 0; i < n; i++) { cin>> num[i]; } qsort(num, n, sizeof(num[0]), cmp); // for(i = 0; i < n; i++) { // cout<< " "<< num[i]; // } // cout<< endl; sum[0] = num[0]; for(i = 0; i < n; i++) { sum[i+1] = sum[i] + num[i]; } cin>> q; for(j = 1; j <= q; j++) { cin>> k; if(res[k] != 0) { cout<< res[k]<< " "; continue; } long long l, r; long long step = k; l = r = 1; ans = 0; for(i = 1; l < n; i++) { r += step; step *= k; if(r > n) { r = n; } long long cur = sum[r] - sum[l]; ans += cur*i; l = r; } res[k] = ans; cout<< ans<< " "; } cout<< endl; } return 0; }