xdoj 1237 (贪心+逆向思维)】的更多相关文章

提示:  当有的元素分裂的同时,其他元素也可以+1 分析: 逆向思维,把当前数列变成一个0: 相应得操作相反: 每个元素减1 相同得两个元素可以合并 设数列中最大的数是max,则一共需要减max次才可以把所有的数字变成零 每次减一的过程 非零元素减一 零元素合并 最后剩余下k个零 再把K个零变成一个零.....半年不看,都忘了当初怎么想的了.自己真是菜 #include<cstring> #include<algorithm> #include <iostream> u…
思路:dp[ i ] 表示 排序后前 i 个元素匹配的最小值, 我们可以发现每个点和它匹配的点的距离不会超过2,这样就能转移啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int,int> #define piii pair<int, pair<int,int> >…
题目大意是在海岸线布置n个雷达,要求雷达的范围要包含所有的小岛: 思路:逆向思维把小岛看成一个个范围,与海岸线的交集,从最左端的开始找 (贪心最左端的点),接着不用一个一个去遍历,直接用前一个的右端点去替换下一个的左端点....直至最后一个点.大致思想就是贪心,还是比较正常的题,适合刚学c语言的新生做(小白我就是一枚). 下面是代码: #include <iostream> #include <cmath> #include <algorithm> #include &…
A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performi…
这道题对于一类题都有一个通用思路:反向递减序列即为正向字典序. 对于逆向思维的题还要多做才能培养这种对于逆向思维的感觉. 想到这种方法之后,就很简单了. 因为n×m不会炸,所以反向LIS叠一个贪心就能过了. 直接甩题目&代码 Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ax 2 < … < axm).那么就称P为S的一个上升序列…
Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the genie will realize one of her dreams. The question is: give you an integer, you are allowed to delete…
1000.a+b. #include<bits/stdc++.h> using namespace std; int a,b; int main() { ios::sync_with_stdio(false); while(~scanf("%d%d",&a,&b)) printf("%d\n",a+b); ; } 1001.不知道n和m大小,可以用一维数组处理位置,或者直接使用vector. #include<bits/stdc++…
题目大意 vjudge链接 给你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值. 样例1输入 5 2 71 11 21 32 32 44 45 2 样例1输出 9 样例2输入 500 500 161 11 21 9991 10002 12 22 9992 10003 13 23 9993 1000499 500499 501499 999499 1000 样例2输出 1008 思路 逆向思维,利用贪心. 假设所有人都还没有上车,所以需要把人们从车门处送回原来的位置. 可以把2…
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][Status][Discuss] Description FJ打算带他的N(1 <= N <= 30,000)头奶牛去参加一年一度的“全美农场主大奖赛”.在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席前依次走过. 今年,竞赛委员会在接受队伍报名时,采用了一种新的登记规则:他们把所…
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…