Codeforces Round #298 (Div. 2)

A - Exam 构造

 1 #include <cstdio>
 2
 3 int ans[5000 + 5];
 4
 5 int main() {
 6     int n, cnt = 1;
 7     scanf("%d", &n);
 8     for (int i = 1; i <= n; i++) {
 9         if (i&1) ans[i] = cnt;
10         else {
11             ans[i] = n+1-cnt;
12             cnt++;
13         }
14     }
15     ans[0] = ans[n];
16     if (n == 1 || n == 2) {
17         printf("1\n1\n");
18         return 0;
19     }
20     if (n == 3) {
21         printf("2\n1 3\n");
22         return 0;
23     }
24     printf("%d\n", n);
25     for (int i = 0; i < n; i++)
26         printf("%d ", ans[i]);
27     return 0;
28 }

B - Covered Path 想法题

 1 #include <cstdio>
 2
 3 inline int min(int a, int b) {
 4     return a < b ? a : b;
 5 }
 6
 7 int main() {
 8     int v1, v2, t, d;
 9     scanf("%d%d%d%d", &v1, &v2, &t, &d);
10     int ans =  0;
11     for (int i = 0; i < t; i++)
12         ans += min(v1+i*d, v2+(t-i-1)*d);
13     printf("%d\n", ans);
14     return 0;
15 }

C - Polycarpus‘ Dice 求上下界

 1 #include <cstdio>
 2
 3 const int N = 100000*2 + 5;
 4 typedef long long ll;
 5 ll ans[N], num[N], suf[N], pre[N];
 6
 7 int main() {
 8     int n;
 9     ll s;
10     scanf("%d%lld", &n, &s);
11     for (int i = 1; i <= n; i++)
12         scanf("%lld", num+i);
13     for (int i = 1; i <= n; i++)
14         pre[i] = pre[i-1] + num[i];
15     for (int i = n; i >= 1; i--)
16         suf[i] = suf[i+1] + num[i];
17     ll can_min, can_max;
18     for (int i = 1; i <= n; i++) {
19         can_min = s - pre[i-1] - suf[i+1];
20         if (can_min < 1) can_min = 1;
21         can_max = s - n + 1;
22         if (can_max > num[i]) can_max = num[i];
23         ans[i] = num[i] - (can_max - can_min + 1);
24     }
25     for (int i = 1; i <= n; i++)
26         printf("%lld ", ans[i]);
27     return 0;
28 }

时间: 2024-08-07 00:03:18

Codeforces Round #298 (Div. 2)的相关文章

Codeforces Round #298 (Div. 2) A、B、C题

题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side

Codeforces Round #298 (Div. 2), problem: (A) Exam

A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspe

Codeforces Round #298 (Div. 2) B. Covered Path

题目大意: 一辆车,每秒内的速度恒定...第I秒到第I+1秒的速度变化不超过D.初始速度为V1,末速度为V2,经过时间t,问最远能走多远. 分析 开始的时候想麻烦了.讨论了各种情况.后来发现每个时刻的最大值都满足一定的约束关系.设此时为时刻i,上一次的速度为p,那么本次的速度应为max(p+d,v2+(t-i)*d),因为要保证最终一定能够返回到v2.这样以来便可以得到每个时刻的最大值,然后累加求和即可. 1 #include<cstdio> 2 #include<iostream>

Codeforces Round #298 (Div. 2) A. Exam(水)

题意:N 个学生 编了号,  然后第i个学生不能和第i+1和第i-1坐在一起,问合法的情况下最多坐多少个人,如何做 题解: 水题YY了一下,打表处理前三种    后面的情况就是在第三种情况下往前后插数字   奇数在后  偶数在前,然后没了 代码: #include<stdio.h> #include<string.h> int main() { int n, mymap[5005]; int mark[3][4] = {{1, 1}, {1, 1}, {2, 1, 3}}; whi

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd