Codeforces Round #298 (Div. 2)

Source: Internet
Author: User

The previous few days of the game, a long time did not do the problem, plus the first few math components, only a question, simply write down.

A. Exam

The difference between two adjacent numbers is greater than 1 for constructing the sequence. It is easy to conclude that, when the number is relatively large, it is perfectly possible to separate the odd and even

E.g:1 3 5 7 9 2 4 6 8 This is no problem, you need to consider a few times the situation is special, 1~4 separately list the answer. Need the main 4 number is can 2 4 1 3 such a row.

I didn't think about 4 numbers correctly, WA took two times.

#include <iostream> #include <cstdio> #include <cstdlib>using namespace Std;int n;int main () {#ifdef Localfreopen ("534a.in", "R", stdin), #endifcin >> n;if (n >= 5) {cout << n << endl;for (int i = 1; I & lt;= N; i+=2) cout << i << '; for (int i = 2; I <= n; i+=2) cout << i << '; cout << Endl;} else {if (n = = 1) cout << "1\n1\n", else if (n = = 2) cout << "1\n1\n"; else if (n = = 3) cout << "2\n1 3\n"; El Se if (n = = 4) cout << "4\n2 4 1 3\n";} return 0;}

  

B. Covered Path

Greedy, to ensure that at the most points on the speed is as large as possible? If time can accelerate to VT, then the obvious optimal solution is to start with the maximum acceleration, and the last time the maximum acceleration (deceleration)

Simulation method to complete, at any time calculate vt+t (remain) XD to ensure that the rest of the time can be slowed down to VT, not too clear, see the Code Bar

#include <iostream>#include<cstdio>#include<cstdlib>using namespacestd;intV0, VT, VH, T, D, S;intMain () {#ifdef LOCAL freopen ("534b.in","R", stdin);#endifCin>> V0 >>VT; CIN>> T >>D; if(V0 >VT) Swap (V0, VT); T-=1; VH=V0; S=V0;  while(VH <= vt+ (t1) *d &&t) {VH+ = min (d, vt+ (t1) *d-VH);//cout << vh << Endl;s + =VH; T--; }     while(VH > VT | |t) {s+=VT; VT+ = min (d, vh-VT);//cout << vh << Endl;t--; } cout<< s <<Endl; return 0;}

C. Polycarpus ' Dice

Math problems, such as the first dice can take 1, 2 then a value range is (1+ left dice to take the smallest) ~ (The dice to take the largest)

Upside down can determine the value range of the dice by the value of a, I do it when I calculate the range of dice

Each value of the dice, get the range of a is regarded as a line segment, the first is (1+ remaining dice to take the smallest) ~ (1+ left dice to take the largest), so that the dice each value constitutes a line segment,

It is arranged in the left-hand coordinates, and then it is the value of a, the number of segments that exist, and the value of the endpoint to be determined.

#include <iostream>#include<cstdio>#include<cstdlib>using namespacestd;Const intMAXN =400000+ -;intN;intD[MAXN];Long LongA, Smin, Smax;intMain () {#ifdef LOCAL freopen ("534c.in","R", stdin);#endifscanf ("%d%lld", &n, &A);  for(inti =0; I < n; i++) {scanf ("%d", d+i); Smin+=1; Smax+=D[i]; }     for(inti =0; I < n; i++) {        intcan; Long LongFl, FR, LL, LR, Vmax; Vmax= (Smax-d[i])-(Smin-1) +1; FL=smin; Fr=1+ Smax-D[i]; ll= D[i] + smin-1; LR=Smax; if(ll <= a && a <=fr) Can=D[i]; Else if(fl <= a && a <=ll) can= min (a-fl +1, Vmax); Elsecan= min (lr-a +1, Vmax); printf ("%d", D[i]-can); } printf ("\ n"); return 0;} 

So-so-so. No one else can read it.

Codeforces Round #298 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.