C - Ilya and Sticks(贪心)】的更多相关文章

Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/C Description In the evening, after the contest Ilya was bored, and he really felt like ma…
题目:click here #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> typedef long long ll; using namespace std; const int M = 1e5+5; int n; int a[M]; int b[M]; bool cmp( int a, int b ) { //从大到小排序 return a >…
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; in…
C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of…
点击打开链接 1270: Wooden Sticks [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 31 解决: 11 统计 题目描述 Lialosiu要制作木棍,给n根作为原料的木棍的长度和重量.根据要求求出制作木棍的最短时间. 首先我们知道制作第一个木棍需要1分钟,若是接着要制作的木棍的重量和长度都不少于当前的木棍,那么就不需要建立的时间,若是没有,则再需要建立时间,也就是1分钟. 举个例子,如果你有五个原料木棍,他们的长度和重量分别是(4,9), (5,2), (2,…
C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of …
Problem description In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li. Ilya decided to make a rectangle fr…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15564    Accepted Submission(s): 6405 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
递增子序列的最小组数.可以直接贪心,扫一遍 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; struct stick{ int h,w; }Sticks[]; bool cmp(stick a,stick b) { return (a.h<b.h)||(a.h==b.h&&(a.w<b.w)…
Wooden Sticks 点我挑战题目 题意分析 给出T组数据,每组数据有n对数,分别代表每个木棍的长度l和重量w.第一个木棍加工需要1min的准备准备时间,对于刚刚经加工过的木棍,如果接下来的木棍l和w均小于等于上一根木棍的l和w那么就不许要准备时间,否则的话还需要1min的准备时间.求解对于每组数据,所需要的最小的准备时间是多少. 贪心策略. 对木棍进行降序排序,首要关键字是l,次要关键字是w(可以颠倒).然后选取最顶端的木棍,向下遍历,对于当前木棍,若l和w均小于等于顶层木棍,那么标记它…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14126    Accepted Submission(s): 5842 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
题目连接:2322 Wooden Sticks 题目大意:给出要求切的n个小木棍 , 每个小木棍有长度和重量,因为当要切的长度和重量分别大于前面一个的长度和重量的时候可以不用调整大木棍直接切割, 否则要进行调整.现在要求求出一个序列, 使得调整的次数最少, 输出调整的次数. 解题思路:将n个小木棍先按照 长度和重量的大小排序,然后按照顺序将小木棍分堆,可入堆的要求是长度和重量大于当前这个堆的长度和重量,入堆之后, 要将新的木棍的属性赋值个这个堆, 如果当前所有堆都没法放下这个木棍, 就得单独放成…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22000    Accepted Submission(s): 8851 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)        Total Submission(s): 23527    Accepted Submission(s): 9551 There is a pile of n wooden sticks. The length and weight of each stick are known in a…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26095    Accepted Submission(s): 10554 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27724    Accepted Submission(s): 11221 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
题目描述 给出若干木棍,每根木棍有特定的颜色和长度.问能否找到三条颜色不同的木棍构成一个三角形.(注意这里所说的三角形面积要严格大于0) 输入 第一行给出一个整数k(3<=k<=50),表示颜色的种数.这k种颜色被标号为1至k.接下来k行,第i+1描述颜色为i的木棍的信息.首先一个整数Ni(1<=Ni<=10^6)表示颜色为i的木棍的数量.接下来Ni个整数,表示这Ni根木棍各自的长度.所有木棍的长度<=10^9.总木棍数量<=10^6. 输出 你的程序应该仅输出一行如果…
木棍 时间限制: 1000MS   内存限制: 10000K 提交总数: 27336   接受: 11857 描述 有一堆木棍.每根杆的长度和重量是预先已知的.这些木棍将由木工机器逐一加工.它需要一些时间,称为设置时间,以便机器准备处理棒.设置时间与清洁操作以及更换机器中的工具和形状相关联.木工机械的安装时间如下: (a)第一根木棒的安装时间为1分钟. (b)在加工长度为l且重量为w的棒之后,如果l <= 1'且w <= w',则机器将不需要设置长度l'和重量w'的设定时间.否则,需要1分钟进…
Wooden Sticks. win the wooden spoon:成为末名. 题目地址:http://poj.org/problem?id=1065 There is a pile of n wooden sticks. a woodworking machine:木工机器. setup time:启动时间. my codes: #include<iostream> #include<cstdio> #include<cstring> #include<al…
(- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.html #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; struct s…
本题一看就知道是最长不减序列了,一想就以为是使用dp攻克了. 只是那是个错误的思路. 我就动了半天没动出来.然后看了看别人是能够使用dp的,只是那个比較难证明其正确性,而其速度也不快.故此并非非常好的解决方法. 所以我就直接硬算.硬模拟选择出非减子序列,选完就出答案了. 思路: 1 依照长度排序 2 依照不减原则选择重量,选一个,消灭一个. 最后消灭完了,就处理完成,答案就自然出来了. 原来是一道披着dp的外套的模拟题啊!一道伪装成难题的简单题. 代码也能够写的非常简洁: #include <s…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用cnt[i]记录数字i出现的次数就好. 然后i从1e6逆序到1 如果cnt[i+1]和cnt[i]>0同时成立的话. 那么得到一条边.加入到vector中. 然后 如果cnt[i]>1 则cnt[i]-=2 加入i到vector中,直到cnt[i]<=1为止. 注意这两个判断的先后顺序. 否则 5 4 4 3会被认为无解. vector的大小如果大于等于2了. 就说明找到一个矩形. [代码] #include <…
#include <iostream>#include<stdio.h>#include<cmath>#include<algorithm>using namespace std;struct product{    int w;    int l;     bool operator<(product &p2)    {        if(w==p2.w)return l<=p2.l;        else return w<…
动态规划与贪心相关: {HDU}{4739}{Zhuge Liang's Mines}{压缩DP} 题意:给定20个点坐标,求最多有多少个不相交(点也不相交)的正方形 思路:背包问题,求出所有的正方形,然后求最多有多少个正方形不互相覆盖,这题真是神思路. {POJ}{3846}{Mountain Road} 题意:给定两个地点车的班次,路是双向单车道,求安排最短的时间 思路:对车次序列进行二维DP转移,转移的时候需要注意时刻的维护.这个题目的DP思路是正向DP,每次遍历到f[i][j]都需要更新…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19672    Accepted Submission(s): 7991 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar…
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10423    Accepted Submission(s): 4287 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar…
由于,这两题有着似乎一样的解法所以将其放在一起总结比較,以达到更好的区分二者的差别所在. 一.区间DP uva的Cutting Sticks是一道典型的模板题. 题目描写叙述: 有一根长度为l的木棍,木棍上面有m个分割点,每一次分割都要付出当前木棍长度的代价,问如何分割有最小代价. 区间DP的定义: 区间动态规划问题一般都是考虑.对于每段区间,他们的最优值都是由几段更小区间的最优值得到,是分治思想的一种应用.将一个区间问题不断划分为更小的区间直至一个元素组成的区间,枚举他们的组合,求合并后的最优…
http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都大于前一根木棍,那么这根木棍不需要生产时间,问你最少的生产时间是多少? 首先可以贪心,先按长度 l排序,如果l相同,按宽度w排序. 从i=0开始,每次把接下来的i+1  -  n-1 的没有标记并且长度和宽度大于等于i这根木棍的长度和宽度标记起来. #include<cstdio> #includ…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:机器运送n个木条,每个木条有一个长度和重量.运送第一根木条需要1分钟的准备时间,接下来如果后一根木条的长度和重量都大于等于前一根木条,则不需要准备时间,否则需要1分钟的准备时间,求运完所有木条最少时间. 比如有5根木条,长度和重量分别是(4,9), (5,2), (2,1), (3,5), (1,4),则需要2分钟就可运完第1分钟运(1,4), (3,5…