Codeforces Round #298 (Div. 2) A B

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 suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.

Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

Input

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

Output

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.

In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 tok - 1.

题意,给出一个n,有1-n这n个数字。让你给出一个序列,这个序列满足|ai - ai + 1| ≠ 1 for all i from 1 tok - 1.

解析:对于小于4的的数据特判,大于等于4的从大到小输出奇数,然后输出偶数。这样就可以满足条件了。


  
  
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <map>
  5. #include <queue>
  6. #include <stack>
  7. #include <algorithm>
  8. #include <cstdlib>
  9. using namespace std;
  10. int main()
  11. {
  12. int n;
  13. cin>>n;
  14. if(n == 1)
  15. printf("1\n1\n");
  16. if(n == 2)
  17. printf("1\n1\n");
  18. if(n==3)
  19. printf("2\n3 1\n");
  20. if(n > 3)
  21. {
  22. printf("%d\n",n);
  23. int i = n % 2 ? n: n -1;
  24. for(; i >0; i -= 2)
  25. printf("%d ",i);
  26. i = n % 2 ? n-1:n;
  27. for(; i > 2;i -= 2)
  28. printf("%d ",i);
  29. printf("2\n");
  30. }
  31. return 0;
  32. }

B. Covered Path
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.

Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.

Input

The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.

It is guaranteed that there is a way to complete the segment so that:

  • the speed in the first second equals v1,
  • the speed in the last second equals v2,
  • the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.
Output

Print the maximum possible length of the path segment in meters.

Sample test(s)
input
5 6
4 2
output
26
input
10 10
10 0
output
100
Note

In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26meters.

In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.

//  题目描述感觉很奇怪,没搞懂什么意思,看了node才懂得。不是物理题。路径最长,先加速,然后减速。WA了两次是

如果v1 和v2开始的差值大于d。这个没有考虑。

方法:设两个指针,l,r,分别从两头开始扫。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
    int v1,v2,t,a;
    cin>>v1>>v2>>t>>a;
    if(v1 > v2)
    {
        int temp = v1;
        v1 = v2;
        v2 =temp;
    }

    int data[110]={};
    int l = 0; int r = t-1;
    data[0] = v1;data[t-1] = v2;
    while(r - l > 1)
    {
        if(data[l] < data[r])
        {
            data[l+1] = data[l] + a;
            l++;
        }
        else
        {
            data[r-1] = data[r] + a;
            r--;
        }
    }
    int sum = 0;
    for(int i = 0; i < t; i++)
      sum += data[i];
    cout<<sum<<endl;
    return 0;
}
 
 
回顾一下,C感觉可以写出来的,被智商碾压,就是没搞出来。

补题C


C. Polycarpus' Dice
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).

For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.

Input

The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.

The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show.

Output

Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.

Sample test(s)
input
2 8
4 4
output
3 3 
input
1 3
5
output
4 
input
2 3
2 3
output
0 1 
题意,给你n个骰子,每个骰子的最大值,一次判断每个骰子有几种面不能出现。就是计算上下限。智商压制a!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值