CDOJ-UESTC 857-Boiling Vegetables
来源:互联网 发布:网络语言的利弊 编辑:程序博客网 时间:2024/04/29 17:44
题意:初始有N颗菜重量分别是w1,...,wn,问你最少切几刀,使得这些菜的最轻和最重的比例符合
思路:师兄做法,考虑到答案说了小于500次,那我们可以用一个优先队列把这些菜记录起来,然后每次选取最重的
菜开始和最轻的比较,如果符合比例就退出来,否则我们就把这个菜i切成++cut[i]份(初始为1),切的
时候是平分,因为切的不均,就会产生大的和小的,会影响结果。所以贪心切。
AC代码:
PS:做法麻烦,仅供参考
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <string.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
const int maxn=5005;
pair<float,float> a[maxn];
float cut[maxn];
int main()
{
float t;
int n;
cin>>t>>n;
for(int i=0; i<n; i++)
{
scanf("%f",&a[i].first);
a[i].second=1;
cut[i]=a[i].first;
}
float*minn,*maxx;
maxx=max_element(cut,cut+n);
minn=min_element(cut,cut+n);
int pos=0;
int ans=0;
while(*minn/(*maxx)<=t)
{
//cout<<*maxx<<' '<<*minn<<' '<<(*minn/(*maxx))<<endl;
pos=maxx-cut;
//cout<<"pos"<<pos<<endl;
int num=++a[pos].second;
*maxx=a[pos].first/num;
maxx=max_element(cut,cut+n);
minn=min_element(cut,cut+n);
ans++;
}
cout<<ans<<endl;
return 0;
}
- CDOJ-UESTC 857-Boiling Vegetables
- CSU 1391 Boiling Vegetables
- 我要长高 UESTC CDOJ
- (CDOJ) UESTC 606 Palindrome Again 后缀数组二分 + Manacher + Hash
- CDOJ(UESTC) 1520 string (这贪心厉害了)
- CDOJ(UESTC)24 8球胜负(eight)~水题
- CDOJ (UESTC) 851 方老师与素数(bfs)
- UESTC CDOJ 1551 Hesty Str1ng 后缀数组+乱搞
- CDOJ (UESTC OJ) 1380 Xiper的奇妙历险(3)
- CDOJ-1591(2017 UESTC Training for Graph Theory -A)
- CDOJ-1592 (2017 UESTC Training for Data Structures B)
- 【持续更新】CDOJ刷题之路 (UESTC) ___ 完成于20130522
- 2016 UESTC Training for Data Structures A - 卿学姐与公主 CDOJ 1324 线段树
- 2016 UESTC Training for Data Structures B - 卿学姐与基本法 CDOJ 1325 线段树+离散化
- 2016 UESTC Training for Data Structures C - 卿学姐与诡异村庄 CDOJ 1328 并查集
- 2016 UESTC Training for Data Structures D - 卿学姐与魔法 CDOJ 1329 堆
- 2016 UESTC Training for Data Structures G - 郭大侠与阴阳家 CDOJ 1337 强行map
- 2016 UESTC Training for Data Structures J - 郭大侠与Rabi-Ribi CDOJ 1334 优先队列
- AI:IPPR的数学表示-CNN结构分析(基本结构)
- linux 基础
- 【C语言】输入指定字符结束循环
- [Python] #!/usr/bin/python 与 #!/usr/bin/env python 的区别
- 有关clipToPadding、 clipChildren的那些事
- CDOJ-UESTC 857-Boiling Vegetables
- C++学习笔记——类与对象
- 【C语言】学生百分制成绩评定
- 基于Django开发的SkyNet博客一
- HDU 2838 Cow Sorting(树状数组求逆序数)
- android机制原理篇-Activity创建过程
- 基于.NET CORE微服务框架 -surging的介绍
- 移除复制粘贴自CSDN博客的代码前面的行号
- matplotlib 一些参数快捷设置