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 ...
随机推荐
- django -- 修改admin 密码问题
1.python manage.py shell 2.from django.contrib.auth.models import User 3.user=User.objects.get(usern ...
- [转载]DLL命名规则
程序集是一个部署单元,同时还代表托管代码程序的身份.一般来说一个程序集仅与一个DLL相对应.本节主要讲DLL命名约定,程序集的命名约定与此类似. 要记住,名字空间与DLL和程序集是不同的概念.名字空间 ...
- 使用BenchmarkSQL测试PostgreSQL
BenchmarkSQL是一款经典的开源数据库测试工具,内嵌了TPCC测试脚本,可以对EnterpriseDB.PostgreSQL.MySQL.Oracle以及SQL Server等数据库直接进行测 ...
- 清明 DAY 1
数学基础 Part 1. 高精度计算 Part 2. 模意义下的运算 mod 对一个数取模,其实就是取余数 注意: • 无除法运算 • ...
- django 数据库html显示
template {% autoescape off %} {% for each in obj %} <h2>{{ each.food }}</h2> <br/> ...
- linux 安装sqlite3
python2个版本导致的问题. 网上找了好多方法都不行. 最后自己莫名其妙弄好了, 回想了一下大概是 安装sqlite3 重新安装python 最后 yum update 更新 就好了.
- Maven 工程读取resource下的文件
1:方式1: public static List<String> userList; static { userList = new LinkedList<String>() ...
- DBeaver连接Oracle11g数据库
DBeaver连接Oracle11g数据库 一.准备 (1)dbeaver管理软件 (2)远程连接数据库地址.用户名秘密等 (3)Oracle驱动:ojdbc6.jar工具包 下载地址:https:/ ...
- HTTP小幺鸡接口管理工具安装与配置说明
http://www.xiaoyaoji.cn/doc/TxybXPTdx 小幺鸡接口管理工具安装说明 使用可以参考:https://blog.csdn.net/qincidong/article/d ...
- opencv学习之路(7)、访问图像像素
一.动态地址访问 #include <opencv2/opencv.hpp> #include<iostream> using namespace cv; using name ...