B - Mister B and Angle in Polygon
Computational Geometry
The meaning of problems
N input points, to create a n-gon, the are connected together (as shown in FIG example) between each point, determine the closest three vertices of a given angle of ∠a angle, b, c , wherein b is a vertex.
answer
Let me talk about ideas under this title, which is not a difficult problem in the code, but not too miss. N-gon and the interior angle is (n-2) * 180 ° , this formula was NATURAL remember. However, it is to some other point they want, ideas outlined as follows: n-gon size of each apex (n-2) * 180 / n ° a pair of vertices of any n-gon, removed itself and two adjacent vertices, the vertices can be fixed to the remaining (n-3) connected to the vertices (n-3) diagonal, the diagonal vertex corresponding to the vertex angle may be divided into (n-3) +1, i.e., (n-2) th sections, each 180 / n ° then n-gon at any angle in the range of three vertices, it is from 180 / n ° ~ 180 * ( n -2) / n °
For convenience output, many solution to a problem on a blog, vertices are based on two front fixing, fixing, for example 21, such as fixed, the answer corresponding to the target angle, and the third number of vertices relationship can be expressed more easily come out
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n , a; cin >> n >> a; double tmp = 180.0 * (n - 2) / n ; double ang = (180.0 - tmp) / 2; double angs = ang; int id = 3; for(int i = 4;i <= n;i ++){ double ans = 1.0 * ang * (i - 2); if(abs(angs - a) > abs(ans - a)){ angs = ans; id = i; } } cout << "2 1 " << id <<endl; return 0; }
C - Mister B and PR Shifts
Recording current array cnt [i] num location to the labeled num [i] location is several times cyclically shifted rightward, two variables add, sub sum would represent the next shift value + 1 / -1 number, each update are performed on the basis of an arrangement.
Note that the first question is intended, 1 <= [i] num <= n.
Note again that for each position of the number, is set num [i], do not look num [i] = = 0 or num [i] n, for the other cases from 1 to num [i] This interval, num [i] to the right so that | num [i] - loc | single down from num [i] n the interval period, num [i] to the right so that | num [i] - loc | monocytogenes; for num [i] = 0, from 1 to n, | num [i] - loc | been monocytogenes; for num [i] = n, num [i] to the right so that | num [i] - loc | Save single; when num [i] moves from n to 1, may not increase or decrease. So for each number num [i], the position num [i] was a turning point, decide the next step | num [i] - loc | how changes (each +1 or -1). Specific ideas See note.
// CodeForces 820D Mister B and PR Shifts 运行/限制:264ms/2000ms #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> using namespace std; #define INF 0x3f3f3f3f #define LL long long int num[1000005],cnt[1000005]; int main(){ int n; int add, sub, index; LL sum, re; while (scanf("%d", &n) != EOF) { SUM= 0 ; the Add = 0 ; Sub = 0 ; Memset (CNT, 0 , the sizeof (CNT)); for ( int I = . 1 ; I <= n-; I ++ ) { Scanf ( " % D " , & NUM [I] ); SUM + = FABS (num [I] - I); cnt [(num [I] - + n-I) n-%] ++; // the labeled cnt: current location num [I] to a num [ i] I need to shift the position of several IF (NUM [i]> I) Sub ++; // next number shift value of -1 will the else the Add ++; // next value will shift number +1 } Re = SUM; index = 0 ; for ( int I = . 1 ; I <n-; I ++) { // each shift on the basis of a pretreatment, i is the first movement times SUM + = the Add - Sub - . 1 ; // this last one is certainly less number satisfying n (n-data range is the maximum), until it was calculated add; but to move to the first place because, it is not necessarily add, subtract sum + = (num [n - I + . 1 ] - . 1 ) - (n-- NUM [n-- I + . 1 ]); // calculate a current change in the last move to the first sum value; // every time does not really shift, but every last one which position should not shift sequences calculated // seek complete sum, the equivalent of the times moved // based on the result of this move, the next update value add, sub occur // -1, +1 is because after this time to move down to the first position, since the monotonicity reversed, so that the Add -1 than normal, sub + 1. // [I] = 1 when num, | num [i] - loc | whole monotonically increasing, the n-position from the position change monotonicity is a special case, can analyze num [n] = 1 satisfies the following formula sub the Add = the Add + CNT [I] - . 1 ; sub = sub - CNT [I] + . 1 ; IF (SUM < Re) { Re = SUM; index = I; } } the printf ( " % LLD% D \ n- " , Re, index); } return 0 ; }
E - Okabe and Banana Trees
Enumeration Y, arithmetic sequence summation
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { // y = -x/m + b long long m , b ; cin >> m >> b; long long maxx = 0; for(int i = b;i >= 0;i --){ long long sum = 0; long long border = m * (b - i); sum=((border+1)*border/2)*(i+1)+(i*(i+1)/2)*(border+1); if(sum > maxx) maxx = sum; } cout << maxx << endl; return 0; }
F - Okabe and Boxes
Thinking, vector simulate what the point: Does not the sort == empty vector
#include <bits/stdc++.h> using namespace std; std::vector<int> v; int main(int argc, char const *argv[]) { int n ; cin >> n ; int cnt = 0,ans = 0; string str; while(cin >> str){ //cnt ++; if(str[0] == 'a'){ int x;cin >> x; v.push_back(x); }else{ cnt++; if(!v.empty()) if(v.back() == cnt) v.pop_back(); else v.clear(),ans++; } } cout << ans << endl; return 0; }