Codeforces Round #492 (Div. 2)

本文提供了三道算法题目的解答及实现思路,包括硬币找零问题、路口通行策略优化和序列调整问题,通过C++代码展示了如何用贪心算法等方法解决实际问题。

A.

/*
从大往小依次除
*/

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<set>
#include<map>
#define M
#define ll long long

using namespace std;
int read() {
    int nm = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
    return nm * f;
}
int main() {
    int n = read(), ans = 0;
    ans += n / 100;
    n %= 100;
    ans += n / 20;
    n %= 20;
    ans += n / 10;
    n %= 10;
    ans += n / 5;
    n %= 5;
    ans += n;
    cout << ans;

    return 0;
}

B.

 

/*
发现每个路口何时进去是能算出来的   所以O1扫一遍即可 


*/


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<set>
#include<map>
#define M 100010 
#define ll long long

using namespace std;
int read() {
    int nm = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
    return nm * f;
}

int note[M]; 

int main() {
    int n = read(), id, minn = 0x3e3e3e3e;
    for(int i = 1; i <= n; i++)
    {
        note[i] = read();
        int op = note[i] - i + 1;
        int zz = (op + n - 1) / n;
        if(zz < minn) minn = zz, id = i;
    }
    cout << id;
    return 0;
}

C.

 

 

 

D.

/*
贪心的写法  每次 选择最靠左的一个不连续的  将右边的贪心移动过来 



*/


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<set>
#include<map>
#define M
#define ll long long

using namespace std;
int read() {
    int nm = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
    return nm * f;
}



int main() {
    


    return 0;
}

 

转载于:https://www.cnblogs.com/luoyibujue/p/9290979.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值