A. Vanya and Cubes
Test instructions
Give you n a small square, now to build a pyramid, the pyramid layer I need a small square, ask the N-block up to a few layers of pyramid.
Analysis:
According to the summation formula, there is, according to the law directly added to the line, until more than N.
1#include <cstdio>2 3 intMain ()4 {5 intN;6scanf"%d", &n);7 intsum =0, cnt =0;8 while(N >sum)9 {Tencnt++; OneSum + = CNT * (CNT +1) /2; A } - if(Sum > N) cnt--; -printf"%d\n", CNT); the - return 0; -}
code June
B. Vanya and Lanterns
Test instructions
There is a road long for L, each lamp coordinates for AI (coordinates origin for the left of the road), each street light illuminates the range of D, requires the whole road can be illuminated, the minimum value of D.
Analysis:
came up to write a two points, decisively timed out.
A different idea:
Sort the position of the N street lights
Because d to illuminate the whole road, so to satisfy:
- The first street light to illuminate the left end of the road, d at least for A0
- Two adjacent streetlights to be illuminated, d at least (ai-ai-1)/2
- The last street light to illuminate the right end of the road, d at least for l-an-1
To satisfy these conditions at the same time, take the maximum value.
1#include <cstdio>2#include <algorithm>3 4 Const intMAXN = ++Ten;5 DoubleA[MAXN], l;6 intN;7 8 intMain ()9 {Tenscanf"%D%LF", &n, &l); One for(inti =0; I < n; ++i) scanf ("%LF", &a[i]); AStd::sort (A, A +n); - - DoubleAns = a[0] -0; the for(inti =1; I < n; ++i) - { -Ans = Std::max (ans, (a[i]-a[i-1])/2); - } +Ans = std::max (ans, l-a[n-1]); -printf"%.10f\n", ans); + A return 0; at}
code June
C. Vanya and Exams (greed)
Test instructions
There are n subjects with a full score of R, each subject has an existing fraction of AI, and each increase in the subject requires writing bi articles. To make the average score not less than AVG, write the minimum number of articles in the article.
Analysis:
Obviously greedy, calculate a still need to improve the score, in the premise of not exceeding the full score to improve the BI small subjects first.
1#include <cstdio>2#include <algorithm>3 4 Const intMAXN =100000+Ten;5 6 typedef __int64 LL;7 8 structExam9 {Ten LL A, b; OneExam (LL a=0, LL b=0): A (a), B (b) {} A BOOL operator< (Constexam& RHS)Const - { - returnb <rhs.b; the } - }EXAM[MAXN]; - - intMain () + { -LL N, R, avg, sum =0; +scanf"%i64d%i64d%i64d", &n, &r, &avg); A for(inti =0; I < n; ++i) at { - LL A, b; -scanf"%i64d%i64d", &a, &b); -Sum + =A; -Exam[i] =Exam (A, b); - } inStd::sort (exam, exam +n); - toLL ans =0, p =0; +LL need = n * avg-sum; - while(Need >0) the { * if(exam[p].a = = r) {p++;Continue; } $LL temp = std::min (need, R-exam[p].a);Panax NotoginsengAns + = temp *exam[p].b; -Need-=temp; thep++; + } Aprintf"%i64d\n", ans); the + return 0; -}
code June
D. Vanya and Computer Game (number theory)
Test instructions
Test instructions not clear, result infinite WA
There are two people who inflict 1 damage on monsters each time, and the Monster's blood volume is a.
They both have X and Y attacks per second, and the attack time is evenly distributed within 1 seconds.
Asked to defeat the Monster, was defeated by WHO, or at the same time by two people defeated.
Analysis:
First of all, we convert the decimal number to an integer, it may be 1 seconds evenly divided into XY unit time
They attack each other every Y, x unit time, causing 1 damage to monsters.
We get a sequence of each attack time for two people.
Y, 2y, 3y,,,,,,
X, 2x, 3x,,,,,,
By sequentially merging two sequences, we can know who the monsters were hit by.
You can use a tag array of 0, 1, and two to record that the first attack was initiated by one person, the second, and both.
It is not difficult to find that the tag array is circular , so only one of the loop sections is required.
The loop length is x/g + y/g, where g = gcd (x, y), noting that when two people attack simultaneously, the monster receives 2 damage.
1#include <cstdio>2 3 typedef __int64 LL;4 Const intMAXN =4000000+Ten;5 CharFLAG[MAXN];6 7 ll GCD (ll A, ll b)8 {9LL r = a%b;Ten while(R) One { AA =b; -b =R; -r = a%b; the } - returnb; - } - + intMainvoid) - { + //freopen ("In.txt", "R", stdin); A LL N, x, y; atscanf"%i64d%i64d%i64d", &n, &x, &y); -LL g =gcd (x, y); -LL p =1, q =1, cnt =1; - while(P <= y/g | | q <= x/g) - { - if(X*p < y*q) in { -p++; toflag[cnt++] =0; + } - Else if(X*p > y*q) the { *q++; $flag[cnt++] =1;Panax Notoginseng } - Else the { +p++; Aq++; theflag[cnt++] =2; + } - } $flag[0] = flag[cnt] =2; $ - for(inti =0; I < n; ++i) - { the LL A; -scanf"%i64d", &a);WuyiA%=CNT; the if(Flag[a] = =0) puts ("Vova"); - Else if(Flag[a] = =1) puts ("Vanya"); Wu ElsePuts"Both"); - } About $ return 0; -}
code June
Codeforces Round #280 (Div.2)