训练赛Round #5 又爆零了 太弱了啊

A题 CodeForces - 1051B

在这里插入图片描述
样例
在这里插入图片描述

思路

区间相邻的两个数⼀定gcd为1,总数为偶数所以答案必然存在,直接取每个相邻的数即可。

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const  int  INF =  0x3f3f3f3f;

int main ()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    long long a,b;
    cin>>a>>b;
    cout<<"YES\n";
    while( a < b )
        cout << a++ << " " << a++ << "\n";
    return 0;
}

B题 CodeForces - 1073D

在这里插入图片描述
在这里插入图片描述

思路

一开始想排序做,然后发现过不了样例2,因为购买是按原来的顺序购买的,例如 4 2 4 2 有 4块的话,他只会买一块。
这样只能暴力加优化,模拟一圈一圈跑,然后跑完一圈后去除在这个圈重复的次数。当一个都买不了的时候就可以break了,这样优化就log级别了。

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const  int  INF =  0x3f3f3f3f;
int a[200100];
int b[200100];
int main ()
{
    int n;
    long long t;
    long long sum = 0 ;
    scanf("%d%lld",&n,&t);
    for (int i = 0 ; i < n ; i++)
        scanf("%d",&b[i]);
    while(1)
    {
        long long cnt = 0;
        long long p = 0 ;
        for (int i = 0 ; i < n ; i++ )
        {
            if ( p + b[i] <= t )
            {
                p+=b[i];
                cnt++;
            }
        }
        if (cnt == 0 )
            break;
        sum += (t/p)*cnt;
        t %= p;
    }
    printf("%lld",sum);
    return 0;
}

D题 AtCoder - abc178_d

在这里插入图片描述
7 3
2 0

题解思路

DP,转移公式 d[i] = d[i] + d[n-3];
0<= n <= i-3;
可以理解为第i个状态都是都之前的i-3的状态加上一个数合成的,i-3确保了这个数大于等于3 。

AC代码

#include <iostream>
#include <cstdio>
using namespace std;
int d[100100];
const int mod = 1e9 + 7;
int main ()
{
    int n;
    cin>>n;
    d[0] = 1;
    for (int i = 1 ; i <= n ; i++ )
        for (int j = 0 ; j <= i - 3 ; j++ )
            d[i] = (d[i] + d[j]) % mod;
    cout<<d[n]<<"\n";
    return 0;
}

E题 AtCoder - abc178_e

在这里插入图片描述
在这里插入图片描述

题解思路

由于在带权并查集做过曼哈顿距离,所以一直想用带权并查集做,但是带权并查集是维护明确点和某点的关,所以没写出来。
想用贪心做,排序Ax + Ay < Bx + By 然后取端点。
结果没想到还有一种情况就是有点变号了,此时我们要用 Ax+By < Ay + Bx
排序,因为无论是X那边变号还是Y那边变号,不会影响结果,我们是取两个端点然后abs(),这样最大的也有可能在最前面,但是不影响结果。

AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const  int  INF =  0x3f3f3f3f;
struct node
{
    int x,y;
}a[200100];
bool cmp (node A,node B)
{
    return A.x+A.y < B.x+B.y;
}
bool cmp1 (node A,node B)
{
    return A.x+B.y < A.y+B.x;
}
int main ()
{
    int n;
    scanf("%d",&n);
    for (int i = 0 ; i < n ; i++ )
    {
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        a[i].x = t1;
        a[i].y = t2;
    }
    sort(a,a+n,cmp);
    int ans = 0 ;
    ans = max(ans,abs(a[n-1].x-a[0].x)+abs(a[n-1].y-a[0].y));
    sort(a,a+n,cmp1);
    ans = max(ans,abs(a[n-1].x-a[0].x)+abs(a[n-1].y-a[0].y));
    cout<<ans<<"\n";
    return 0;
}

F题 AtCoder - abc204_e

在这里插入图片描述
在这里插入图片描述

题解思路

AC代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值