CF #298 Div2

A:

题意:

给一个数n,要求输出相邻俩数相差超过1的一个排列。

e.g 3 1 4 2.

解析:

这组数据太坑了,直接加入特判。

然后剩下的,按照先奇数排,后偶数排,就好了。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
#define lson lo, mi, rt << 1
#define rson mi + 1, hi, rt << 1 | 1

using namespace std;
const int maxn = 50000;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);

int ans[maxn];

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    int n;
    cin >> n;
    int cnt = 0;
    if (n == 2)
    {
        printf("1\n1\n");
    }
    else if (n == 4)
    {
        printf("4\n3 1 4 2\n");
    }
    else
    {
        for (int i = 1; i <= n; i += 2)
        {
            ans[cnt++] = i;
        }
        if (ans[cnt - 1] - 1 == 2)
        {
            printf("%d\n", cnt);
            for (int i = 0; i < cnt; i++)
                printf("%d ", ans[i]);
        }
        else
        {
            for (int i = 2; i <= n; i += 2)
            {
                ans[cnt++] = i;
            }
            printf("%d\n", cnt);
            for (int i = 0; i < cnt; i++)
                printf("%d ", ans[i]);
        }
    }

//    }
    return 0;
}

B:

题意:

给一个初速度v1,末速度v2,行驶时间t,每个间断时间内的最大加速度d(速度每次可以加到1~d)。

求行驶的最大路程。

解析:

校赛这题脑残竟然没有A出来,作死。

首先明确的一点是,以最大加速度往上加到最大,然后再以最大速度减到v2速度,一定是路程最大的。

由v1开始用最大速度往上加,每次加的时候判断当前到末速度的间隔的减速是否能减到v2。

然后直接反回来从v2开始加回去就行了。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
#define lson lo, mi, rt << 1
#define rson mi + 1, hi, rt << 1 | 1

using namespace std;
const int maxn = 50000;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    int v1, v2, t, d;
    cin >> v1 >> v2 >> t >> d;
    int ans = v1 + v2;
    int cnt = 2;
    while (v1 + d - (t - cnt) * d < v2)
    {
        cnt++;
        v1 += d;
        ans += v1;
//        cout << ans << endl;
    }
//    cout << cnt << endl;
    cnt = t - cnt;
    while (cnt--)
    {
        v2 += d;
        ans += v2;
    }
    cout << ans << endl;
    return 0;
}

C:

题意:

给n,并且n个数的和sum。

然后给n个数能够取到的最大值。

求每个数和为sum的情况下不能取到的数的个数。

比如

1 3

5

这个数最大可以取到5,也就是说1,2,3,4,5都可以取到,但sum为3,所以5不能取到的数为(1,2,4,5)4个。

解析:

用条件求出当前这个数能取到的最大值和最小值,减一减就算出不能取到的数的个数了。

最大的数和为aSum。

未加这个数字的时候,最大可以达到aSum - a[i],最小可以达到n - 1,因此:

当前这个数能取到的最小值 lo = sum - (aSum - a[ i ]) 最大值hi = sum - (n - 1)。

然后求下个数加起来就行了。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
#define lson lo, mi, rt << 1
#define rson mi + 1, hi, rt << 1 | 1

using namespace std;
const int maxn = 2 * 1e5 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);

LL a[maxn];

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    LL n, sum;
    scanf("%I64d%I64d", &n, &sum);
    LL aSum = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%I64d%", &a[i]);
        aSum += a[i];
    }
    for (int i = 0; i < n; i++)
    {
        LL lo = sum - (aSum - a[i]);
        LL hi = sum - (n - 1);
        //cout << lo << " " << hi << endl;
        LL ans = 0;
        if (0 < lo)
        {
            ans += lo - 1;
        }
        if (hi < a[i])
        {
            ans += a[i] - hi;
        }
        printf("%I64d ", ans);
    }
    printf("\n");
    return 0;
}

D:

题意:

有n个人进屋子,进屋子的时候要和屋里的每个人握手,每三个人可以组成一个队伍离开这个屋子。

现在给这些人进屋以后的握手次数,求这些人进入屋子的顺序。

解析:

贪心,满三人减,满三人减。见代码。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
#define lson lo, mi, rt << 1
#define rson mi + 1, hi, rt << 1 | 1

using namespace std;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);

vector<int> vec[maxn];
int ans[maxn];

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif // LOCAL
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int x;
        scanf("%d", &x);
        vec[x].push_back(i);
    }

    int now = 0;
    bool flag = true;
    for (int i = 0; i < n; i++)
    {
        while (vec[now].size() == 0 && now >= 0)
            now -= 3;
        if (now < 0)
        {
            flag = false;
            break;
        }
        ans[i] = vec[now].back();
        vec[now].pop_back();
        now++;
    }
    if (flag)
    {
        printf("Possible\n");
        printf("%d", ans[0]);
        for (int i = 1; i < n; i++)
        {
            printf(" %d", ans[i]);
        }
        printf("\n");
    }
    else
    {
        printf("Impossible\n");
    }
    return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值