woj 1567 - D - Sloth's Angry(贪心)

题意:

思路:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctype.h>
#define LL __int64
using namespace std;
const int MAXN=1000+5;
const int INF=0x3f3f3f3f;
int a[MAXN],id,n;
bool judge(int a[])
{
    int Minn=INF;
    for(int i=0;i<n;i++)
        if(a[i]!=0 && a[i]<Minn)
        {
            Minn=a[i];
            id=i;
        }
    if(Minn==INF) return false;
    else return true;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        int minn=INF;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]<minn) minn=a[i];
        }
        int cnt=1;
        for(int i=0;i<n;i++) a[i]=a[i]-minn;

        while(judge(a))
        {
            int minnum=a[id];
            for(int i=id;i>=0;i--)
            {
                if(a[i]==0) break;
                a[i]=a[i]-minnum;
            }
            for(int i=id+1;i<n;i++)
            {
                if(a[i]==0) break;
                a[i]=a[i]-minnum;
            }
            cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

  

woj 1567 - D - Sloth's Angry(贪心)

时间: 2024-10-12 21:05:40

woj 1567 - D - Sloth's Angry(贪心)的相关文章

Problem 1567 - D - Sloth&#39;s Angry ( 递归+贪心)

Problem 1567 - D - Sloth's Angry Time Limit: 1000MS Memory Limit: 65536KB Total Submit: 326 Accepted: 113 Special Judge: No Description A forest is full of sloths, they are so eager for tree leaves and as a result, very angry. We assume that the fore

15.4.19 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛

Problem 1564 - A - Circle Time Limit: 4000MS   Memory Limit: 65536KB   Total Submit: 349  Accepted: 73  Special Judge: No Description Here is a circle sequence S of length n, and you can choose a position and remove the number on it. After that,you w

woj 1565 - B - Magic (贪心+dp)

#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<queue> #include<algorithm> using namespace std; int a[1000000+10]; char str[1000000+10]; int main() { int n; int i,j

ACM学习历程—HDU 4726 Kia&#39;s Calculation( 贪心&amp;&amp;计数排序)

DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds 9. For example, when she calculates 4567+5789, she will get 9246, and for 12

Codeforces Round #335 (Div. 2) D. Lazy Student 贪心

D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to hi

K - Kia&#39;s Calculation(贪心)

Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number

【uva 1615】Highway(算法效率--贪心 区间选点问题)

题意:给定平面上N个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个店,都有一个选出的点离它的欧几里德距离不超过D. 解法:先把问题转换成模型,把对平面的点满足条件的点在x轴的直线上可得到一个个区间,这样就是选最小的点覆盖所有的区间的问题了.我之前的一篇博文有较详细的解释:关于贪心算法的经典问题(算法效率 or 动态规划).代码实现我先空着.挖坑~

【贪心+Treap】BZOJ1691-[Usaco2007 Dec]挑剔的美食家

[题目大意] 有n头奶牛m种牧草,每种牧草有它的价格和鲜嫩度.每头奶牛要求它的牧草的鲜嫩度要不低于一个值,价格也不低于一个值.每种牧草只会被一头牛选择.问最少要多少钱? [思路] 显然的贪心,把奶牛和牧草都按照鲜嫩度由大到小排序,对于每奶牛把鲜嫩度大于它的都扔进treap,然后找出后继. 不过注意后继的概念是大于它且最小的,然而我们这里是可以等于的,所以应该是找cow[i].fresh-1的后继,注意一下…… 1 #include<iostream> 2 #include<cstdio&

POJ1017 Packets(贪心算法训练)

Time Limit: 1000MS          Memory Limit: 10000K          Total Submissions: 51306          Accepted: 17391 Description A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These pro