Codeforces Round #552 (Div. 3)-D-Walking Robot-(贪心)

http://codeforces.com/contest/1154/problem/D

解题:

1.无光的时候优先使用太阳能电池。

2.有光的时候

(1)太阳能电池没满电,让它充,使用普通电池

(2)太阳能电池满电,使用太阳能电池

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;

int n,a,b;
int s[200005];

int main()
{
    while(scanf("%d%d%d",&n,&a,&b)!=EOF)///路段 普通电池 太阳能电池
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&s[i]);
        int maxx=b;
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            if(s[i]==0)///无光
            {
                if(b)///优先使用太阳能电池
                {
                    b--;
                    sum++;
                }
                else if(a)///其次使用普通电池
                {
                    a--;
                    sum++;
                }
                else
                    break;
            }
            else ///有光
            {
                if(b==maxx)///太阳能满了就优先使用它
                {
                    b--;
                    sum++;
                }
                else if(a)///太阳能没满就让太阳能充电,用普通电池
                {
                    b++;
                    sum++;
                    a--;
                }
                else if(b)///太阳能没满,但是普通电池已经用完了
                {
                    b--;
                    sum++;
                }
                else
                    break;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/shoulinniao/p/10835921.html

时间: 2024-08-03 10:30:28

Codeforces Round #552 (Div. 3)-D-Walking Robot-(贪心)的相关文章

Codeforces Round #552 (Div. 3) C题

题目网址:http://codeforces.com/contest/1154/problem/C 题目意思:小猫吃三种食物,A,B,C,一周吃食物的次序是,A,B,C,A,C,B,A,当小猫该天无食物可吃时,就会饿死,现给出a,b,c三个数,表示A,B,C的食物数量, 选择一天开始,问小猫最多可以活到多少天. 题解:首先,在一周时间,A要吃三天,B要吃两天,C要吃两天,先随便选一天开始,当剩下食物不足以撑过一周时停止,再细分剩下的食物数量,看小猫饿 死是经过的最多天数.选择的天数用暴力写即可.

Codeforces Round #552(div.3)

Problem: http://codeforces.com/contest/1154 A: 1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9

Codeforces Round #552 (Div. 3) Editorial 1154C - Gourmet Cat

链接:https://codeforces.com/contest/1154/problem/C 题意:一只旅行的小猫在特定的星期里吃特定的食物,一四七a,二六b,三五c,现在给三种食物的数量,问小猫最多能活几天. 思路:先看小猫能活几个整星期,因为a在一个星期里占三天,b和c各占两天,所以取min(a/3,b/2,c/2),然后求剩下的,这个时候就可以枚举日子了,从周一枚举到周日,然后模拟一哈就行了,虽然是个水题但我还是没做粗来 代码: 1 //#include<bits/stdc++.h>

Codeforces Round #552 (Div. 3)-1154E-Two Teams-(模拟+双指针)

http://codeforces.com/contest/1154/problem/E 解题: 举例n=10,k=1 1,2,10,4,7,6,9,8,5,3 第一次,1队先挑2,10,4这三个人 1,2,10,4,7,6,9,8,5,3 第二次,2队挑6,9,8三个人 1,2,10,4,7,6,9,8,5,3 第三次,1队挑1,7,5三个人 1,2,10,4,7,6,9,8,5,3 第四次,2队挑3一个人 1,2,10,4,7,6,9,8,5,3 显然需要实现的有两点 (1)挑完后的“连接”

Codeforces Round #501 (Div. 3) D Walking Between Houses

翻译 给你一条数轴(出题人很喜欢数轴啊),上面有排列着\(n\)个点,编号为\(1\)到\(n\)(你开始在\(1\)).每次你要从一个点移动到另一个点(可以重复).移动距离为两点坐标之差的绝对值,问你是否能否在\(k\)次机会内里一共移动\(s\)距离,并输出方案. 思路 第四题还是比较难的,赛后想了几分钟时才有头绪. 毫无疑问还是贪心(出题人很喜欢贪心啊)!那么我们分类讨论,先看不合法的情况 无论如何走你也走不到那个距离 无论如何走你也会走超那个距离 看来只要能走到那个距离除外都是不合法的,

Codeforces Round #552 (Div. 3) E C++

题目: E. Two Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the

Codeforces Round #140 (Div. 1) Naughty Stone Piles 贪心

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 1000010; __int64 sum[maxn] ; __int64 num[maxn]; __int64 ans[maxn]; __int64 vis[maxn] ; __int64 qu

Codeforces Round #140 (Div. 1)D The table 贪心

#include<iostream> #include<cstdio> #include<cstring> using namespace std ; const int maxn = 110 ; int sum_r[maxn] ; int sum_c[maxn] ; int vis_c[maxn] ;int vis_r[maxn] ; int ans_c[maxn] ;int ans_r[maxn] ; int table[maxn][maxn] ; void ini

Codeforces Round #276 (Div. 1)D.Kindergarten DP贪心

D. Kindergarten In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a