摘要:过河问题时间限制:1000 ms | 内存限制:65535 KB难度:5描述在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边。如果不借助手电筒的话,大家是无论如何也不敢过桥去的。不幸的是,N个人一共只带了一只手电筒,而桥窄得只够让两个人同时过。如果各自单独过桥的话,N人所需要的时间已知;...
阅读全文
摘要:#include#includeusing namespace std;int a[1000100];int main(){ int i,n,high; while(scanf("%d",&n)!=EOF) { for(i=0;i=0;i--)//i=n/2-1容易出错 { if(a[i]*2<=a[high]) { ans--; high--; } } printf("%d\n",ans); ...
阅读全文
摘要:#include#includeusing namespace std;#define Max 40struct Node{ int x,y; bool flag;} p[Max];bool cmp(Node p1, Node p2){ if(p1.y#includeusing namespace std;#define Max 40struct Node{ int x,y; bool flag;}p[Max];/*bool cmp(Node p1,Node p2){ if(p1.xans) ans=num; for(i=0;i<n;i+...
阅读全文
摘要:题解: 首先要读懂题意:一个导弹拦截系统不一定要连续发射; 按先后顺序处理发射来的导弹, 1.用a[i]来保存第i个拦截系统当前的发射高度(目前需m个拦截系统); 2.对于发射来的导弹,其高度若比1~m中的任一a[i]小,则更新a[i],即 第i个拦截系统当前的发射高度,若其高度比所有的a[i]都大,则需一个新的 拦截系统a[m+1],保存发射来的导弹高度。DP也能做:不过,我不在行@@#include<stdio.h>#include<string.h>#define ...
阅读全文
摘要:题解: 对Alice和Bob的数据一起排序,再贪Alice离Bob最进的矩形 做了整整一个下午,我晚饭后找了一会,还是没发现, 一筹莫展之际,只有使出杀手锏(求教飞机哥!!!) 正在注释代码准备求助时,终于的发现了坑货的小bug!!!! ( bool cmp()中忘写了return false;以前使用int cmp()) 1。起初是直接查找TLE,各种换数据结构。 2。数组开100005提交,Runtime Error (ACCESS_VIOLATION) 又百度,此错误好像有爆内存的原因(明明就够题目数据量的??)。 3。最...
阅读全文
摘要:枚举的错误:View Code #include<stdio.h>#include<algorithm>using namespace std;struct Node{ int s;//time start int e;// end int c;//money}N[1010];bool cmp(Node a,Node b){ if(a.s<b.s)return true; else if(a.s==b.s&&a.c>b.c)return true; return false;}int main(){ int T,m,n; int max,mx
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[10001][101];//纸数组typedef struct Node{ int ik,ii;}mi;//最后一排有的连续空格bool cmp(Node a,Node b){ if(a.ik>b.ik) return true; return false;}int main(){ int N,L,M; int i,j; int res,k,ki,ans; while(...
阅读全文
摘要:题目: 有n个区间,[ai, bi),统计不相交区间最多有多少个?贪心策略: 将这n个区间按bi由小到大排序,然后从前向后遍历,每当遇到不相交的区间就加入目标集合,遍历完成后就找到了最多的不相交区间。具体证明,上篇博客有:#include<stdio.h>#include<algorithm>using namespace std;struct Node{ int s,e;}N[105];bool cmp(Node a,Node b){ if(a.e<b.e)return true; //else return a.s<b.s; return false;}
阅读全文
摘要:选择不相交区间(转) 数轴上有n个区间[ai,bi],要求选择尽量多个区间,使得这些区间两两没有公共点。贪心策略: 按照b1<=b2<=b3…的方式排序,然后从前向后遍历,每当遇到可以加入集合的区间,就把它加入集合。(集合代表解的集合)证明: 我们对a1,a2……的关系分以下几种情况考虑: 1、a1>a2。 此时区间2包含区间1。这种情况下显然不会选择区间2,因为选择区间1会留下更多的剩余空间。 不仅区间2如此,以后所有区间中只要有一个 i 满足a1 > ai,i 都不要选。 即此种情况下,选择区间1是明智的,与策略一致。 ...
阅读全文
摘要:思路: 把走廊分为200段,记录每段被通过的次数,如果哪段通过次数最多,那么其自然耗费最多的时间(不可能2个人同时通过这一段)!#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int s[201]; int T,n; int a,b,t; scanf("%d",&T); while(T--) { memset(s,0,sizeof(s)); scanf("%d",&n); whil
阅读全文