day4 CodeForces 589F Gourmet and Banquet
2016-08-02 23:05
134 查看
题目是要求每道菜都能吃的最大区间,首先可以将区间按照右端点排序,可以让当前区间队后面区间的影响最低,之后从最大区间往下扫找到符合的答案就可以了
#include"iostream"
#include"memory.h"
#include"algorithm"
using namespace std;
int n;
struct node{
int l,r;
};
node d[10005];
int v[10005];
int cmp(const node& a,const node& b)
{
return (a.r<b.r)||(a.r==b.r&&a.l<b.l);
}
int test(int x)
{
memset(v,0,sizeof(v));
for(int i=1;i<=n;i++)
{
int sum=0;
for(int j=d[i].l+1;j<=d[i].r;j++)
if(!v[j])
{
v[j]=1;
sum++;
if(sum==x) break;
}
if(sum<x) return 0;
}
return 1;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>d[i].l>>d[i].r;
//for(int i=0;i<n;i++) cout<<d[i].l<<d[i].r<<endl;
sort(d+1,d+n+1,cmp);
//for(int i=0;i<n;i++) cout<<d[i].l<<d[i].r<<endl;
int hi,lo,mid;
lo=1;
hi=10000+1;
while(!test(hi)&&hi>0) hi--;
if(test(hi)) cout<<hi*n<<endl;
else cout<<0<<endl;
}
#include"iostream"
#include"memory.h"
#include"algorithm"
using namespace std;
int n;
struct node{
int l,r;
};
node d[10005];
int v[10005];
int cmp(const node& a,const node& b)
{
return (a.r<b.r)||(a.r==b.r&&a.l<b.l);
}
int test(int x)
{
memset(v,0,sizeof(v));
for(int i=1;i<=n;i++)
{
int sum=0;
for(int j=d[i].l+1;j<=d[i].r;j++)
if(!v[j])
{
v[j]=1;
sum++;
if(sum==x) break;
}
if(sum<x) return 0;
}
return 1;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>d[i].l>>d[i].r;
//for(int i=0;i<n;i++) cout<<d[i].l<<d[i].r<<endl;
sort(d+1,d+n+1,cmp);
//for(int i=0;i<n;i++) cout<<d[i].l<<d[i].r<<endl;
int hi,lo,mid;
lo=1;
hi=10000+1;
while(!test(hi)&&hi>0) hi--;
if(test(hi)) cout<<hi*n<<endl;
else cout<<0<<endl;
}
相关文章推荐
- day4 CodeForces 27E Number With The Given Amount Of Divisors
- day4 CodeForces 616A Comparing Two Long Integers
- codeforces 180D
- CodeForces 257B Playing Cubes
- [CodeForces 607A]Chain Reaction[DP]
- 【模拟】Codeforces 706A Beru-taxi
- CodeForces 586D Phillip and Trains(搜索)
- Fake NP (Codeforces - 805A)
- CodeForces - 812B Sagheer, the Hausmeister (dp)
- [刷题笔记] Codeforces 115B ,一个清楚的大脑
- map--codeforces,519D.
- codeforces 625C K-special Tables
- CodeForces 547B (单调栈)
- 【Codeforces-402B】-Weird Rounding(数学,思维)
- Codeforces 839E Mother of Dragons【__builtin_popcount()的使用】
- CodeForces:#448 div2 B. XK Segments
- codeforces 127 div2
- 【Codeforces】 CF 520C DNA Alignment
- CodeForces - 630G Challenge Pennants (组合数学)
- CodeForces 115A Party