UVALive 6611 Alice's Print Service(二分)
2016-07-30 23:12
274 查看
思路:二分二分就好了
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define INF 0x3f3f3f3f
#define esp 1e-9
typedef long long LL;
using namespace std;
const int N=1e5+10;
int n,m,T,a
,b
;
struct node
{
LL v;
int i;
bool operator < (const node&a)const
{
return v<a.v;
}
};
node s
;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%d%d",a+i,b+i);
a
=2*1e9;
b
=2*1e9;
int k=0;
s[0].v=(LL)a
*b
;
s[0].i=n;
for(int i=n-1;i>=0;i--)
{
if((LL)a[i]*b[i]<s[k].v)
{
s[++k].v=(LL)a[i]*b[i];
s[k].i=i;
}
}
k++;
sort(s,s+k);
while(m--)
{
int x;
scanf("%d",&x);
int y=upper_bound(a,a+n+1,x)-a-1;
LL ans=(LL)x*b[y];
int z=upper_bound(s,s+k,node{ans,0})-s-1;
if(s[z].i>y) ans=s[z].v;
printf("%lld\n",ans);
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define INF 0x3f3f3f3f
#define esp 1e-9
typedef long long LL;
using namespace std;
const int N=1e5+10;
int n,m,T,a
,b
;
struct node
{
LL v;
int i;
bool operator < (const node&a)const
{
return v<a.v;
}
};
node s
;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%d%d",a+i,b+i);
a
=2*1e9;
b
=2*1e9;
int k=0;
s[0].v=(LL)a
*b
;
s[0].i=n;
for(int i=n-1;i>=0;i--)
{
if((LL)a[i]*b[i]<s[k].v)
{
s[++k].v=(LL)a[i]*b[i];
s[k].i=i;
}
}
k++;
sort(s,s+k);
while(m--)
{
int x;
scanf("%d",&x);
int y=upper_bound(a,a+n+1,x)-a-1;
LL ans=(LL)x*b[y];
int z=upper_bound(s,s+k,node{ans,0})-s-1;
if(s[z].i>y) ans=s[z].v;
printf("%lld\n",ans);
}
}
return 0;
}
相关文章推荐
- UVAlive 6611 Alice's Print Service 二分
- hdu 4791 Alice's Print Service(二分)
- HDU 4791 Alice's Print Service(二分)
- hdoj 4791 Alice's Print Service(二分)
- ZOJ3726 Alice's Print Service(二分)
- 文章标题 HDU 4791 :Alice's Print Service(二分+dp)
- HDU 4791 Alice's Print Service【二分查找】
- zoj-3726-Alice's Print Service【二分+rmq】
- HDU 4791 Alice's Print Service(二分)——2013 Asia Changsha Regional Contest
- UVALive 5000 Underwater Snipers --二分
- UVA Live 6557 Stampede! (uestc oj 871) 最大流+二分
- UVALive 6656 Watching the Kangaroo --二分
- 【UVALive3635】Pie(浮点二分)
- UVALive_6168_Fat Ninjas(二分+并查集)
- UVALive 3971 Assemble 电脑配件 二分+贪心
- [UVALive7261]A - Xiongnu's Land (二分)
- UVALive - 4254 Processor 二分+优先队列
- UVALive 3608 Period(二分答案+DP)
- UVA Live 3211飞机调度问题-二分+2-SAT
- UVALive 3635-Pie-二分