Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数据超弱,这样也过...In Reply To:Re:这题是什么意思啊,高人指点一下,谢了!!! Posted by:yuanyirui at 2007-03-13 13:04:53 #include <stdio.h> #include <iostream> using namespace std; struct Inv{ int be,en; bool friend operator <(Inv a,Inv b) { return a.en < b.en; } }inv[10010]; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int i,j,n,ans,el[2]; while(scanf("%d",&n)!=EOF){ for(i=0;i<n;i++) scanf("%d%d",&inv[i].be,&inv[i].en); sort(inv,inv+n); ans=2; el[0]=inv[0].en-1 , el[1]=inv[0].en; // 需要满足的两个元素 for(i=1;i<n;i++){ if(inv[i].be<=el[0] && el[0]<=inv[i].en){//两个都在里面 } else if(inv[i].be<=el[1] && el[1]<=inv[i].en){//只有一个 el[0]=el[1]; el[1]=inv[i].en; ans++; } else { //一个都没有 el[0]=inv[i].en-1; el[1]=inv[i].en; // 数据超弱。。换成 el[1]=inv[0].en 也过 ans+=2; } } printf("%d\n",ans); } return 1; } /* 0 1 2 3 4 5 6 7 ----- (0 to 2) ----- (2 to 4) ------- (3 to 6) ------- (4 to 7) (1,2,4,7) */ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator