Codeforces 767D - Cartons of milk
题目链接:http://codeforces.com/contest/767/problem/D
D比C水系列。
将商店里面的牛奶按照保质期升序排序(显然优先买保质期久的)考虑二分答案,然后再将整个序列归并排序,贪心的检测答案是否正确即可。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 2001000
#define llg int
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,a[maxn],b[maxn],c[maxn],ans,tail,k; inline llg getint()
{
llg res=,fh=;char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')fh=-,ch=getchar();
while(ch<=''&&ch>='')res=res*+ch-'',ch=getchar();
return res*fh;
} struct node
{
llg val,wz;
}e[maxn]; bool cmp(llg a,llg b){return a>b;} bool cmpp(const node&a,const node&b){return a.val>b.val;} inline bool check(llg r2)
{
llg r1=n;
llg w1=,w2=; tail=;
while (w1<=r1 || w2<=r2)
{
if (w1>r1) c[++tail]=b[w2],w2++;
else if (w2>r2) c[++tail]=a[w1],w1++;
else if (a[w1]>b[w2])
{
c[++tail]=a[w1],w1++;
}
else
{
c[++tail]=b[w2],w2++;
}
}
llg x=tail+,t=;
while ()
{
for (llg i=;i<=k;i++)
{
x--;
if (x<=) return ;
if (c[x]<t) return ;
}
t++;
}
return ;
} int main()
{
yyj("D");
cin>>n>>m>>k;
for (llg i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a+n+,cmp);
for (llg i=;i<=m;i++)
{
scanf("%d",&b[i]);
e[i].val=b[i],e[i].wz=i;
}
sort(b+,b+m+,cmp);
sort(e+,e+m+,cmpp);
llg l=,r=m,mid;
ans=-;
while (l<=r)
{
mid=(l+r)>>;
if (check(mid)) {ans=mid,l=mid+;}else r=mid-;
}
cout<<ans<<endl;
for (llg i=;i<=ans;i++) printf("%d ",e[i].wz);
return ;
}
Codeforces 767D - Cartons of milk的更多相关文章
- 【codeforces 767D】Cartons of milk
[题目链接]:http://codeforces.com/problemset/problem/767/D [题意] 每个牛奶都有最晚可以喝的时间; 每天喝K瓶牛奶; 你有n瓶牛奶->已知每个牛 ...
- Codeforces Round #398 (Div. 2)
Codeforces Round #398 (Div. 2) A.Snacktower 模拟 我和官方题解的命名神相似...$has$ #include <iostream> #inclu ...
- Codeforces Round #398 (div.2)简要题解
这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...
- Codeforces Round #398 (Div. 2) A,B,C,D
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #398 (Div. 2) A B C D 模拟 细节 dfs 贪心
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #398 (Div. 2) A-E
分数史上新低 开场5分钟过了A题,想着这次赌一把手速,先去切C吧 看完C题觉得这应该是道水题,码了十分钟提交,WA 想着这明明是道水题,估计少考虑了情况,添了几行再交,WA 不可能啊,这题都A不掉,和 ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- 【15.07%】【codeforces 625A】Guest From the Past
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
随机推荐
- Symfony2 学习笔记之控制器
一个controller是你创建的一个PHP函数,它接收HTTP请求(request)并创建和返回一个HTTP回复(Response).回复对象(Response)可以是一个HTML页面,一个XML文 ...
- Django框架----ORM数据库操作注意事项
1.多对多的正向查询 class Class(models.Model): name = models.CharField(max_length=32,verbose_name="班级名&q ...
- linux系统Centos环境下搭建SVN服务器及权限配置
linux系统Centos环境下如何搭建SVN服务器以及svnserve.conf.authz.passwd配置文件详细介绍 至于svn的概念,这里就不做详细阐述了,可以自行百度.简单来讲就是一个 ...
- TF-IDF基本原理
1.TF-IDF介绍 TF/IDF(term frequency–inverse document frequency)用以评估字词 对于一个文件集其中一份文件的重要程度.字词的重要性随着它在文件中出 ...
- Sqring核心概念
Spring 是大规模企业级框架,用户数量多,数据规模大,功能众多,业务复杂, 性能和安全要求高 灵活多变 Spring框架是轻量级的框架,javaEE的春天,当前主流的框架,一站式的企业应用开 ...
- FFMPEG结构体分析:AVFrame(解码后的数据)
https://blog.csdn.net/jxcr1984/article/details/52766524 本文转自: http://blog.csdn.net/leixiaohua1020/ar ...
- python协程之动态添加任务
https://blog.csdn.net/qq_29349715/article/details/79730786 python协程只能运行在事件循环中,但是一旦事件循环运行,又会阻塞当前任务.所以 ...
- PHP获取Linux当前目录下文件并实现下载功能
使用nginx转发过去给php server{ listen 9099; server_name 18.5.6.2; location / { proxy_http_version 1.1; root ...
- PT,PX,DPI
[iOS]查找数组NSArray中是否包含指定的元素 http://blog.csdn.net/zyq527758142/article/details/51278172 Dpi(每平方英寸像素数目) ...
- 01 Hello World!
from tkinter import Label#获取组件对象 widget=Label(None,text='Hello GUI world!')#生成 widget.pack()#布置 widg ...