Codeforces Round #437 Div. 1
A:显然构造一组只包含1和2面值的数据即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
} signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
int n=read();
cout<<n*2-1<<' '<<2<<endl;
cout<<1<<' '<<2;
return 0;
//NOTICE LONG LONG!!!!!
}
B:显然两种pizza的分配应尽可能贴近第二种更优和第一种更优的人数关系。于是在这个边界附近±1暴力枚举一下,然后贪心非常显然。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m;
ll t=0,ans=0;
struct data
{
int x,y,z;
bool operator <(const data&a) const
{
return y-x>a.y-a.x;
}
}a[N];
bool cmp(const data&x,const data&y)
{
return abs(x.y-x.x)>abs(y.y-y.x);
}
void check(ll k)
{
if (k<0||k>t) return;
ll x=1ll*k*m,y=(t-k)*m,s=0;
for (int i=1;i<=n;i++)
if (a[i].y>a[i].x)
{
if (a[i].z<=x) s+=1ll*a[i].y*a[i].z,x-=a[i].z;
else if (x) s+=1ll*a[i].y*x,s+=1ll*a[i].x*(a[i].z-x),y-=a[i].z-x,x=0;
else s+=1ll*a[i].x*a[i].z,y-=a[i].z;
}
else
{
if (a[i].z<=y) s+=1ll*a[i].x*a[i].z,y-=a[i].z;
else if (y) s+=1ll*a[i].x*y,s+=1ll*a[i].y*(a[i].z-y),x-=a[i].z-y,y=0;
else s+=1ll*a[i].y*a[i].z,x-=a[i].z;
}
ans=max(ans,s);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) t+=a[i].z=read(),a[i].x=read(),a[i].y=read();
sort(a+1,a+n+1);
t=(t-1)/m+1;
ll x=0;for (int i=1;i<=n;i++) if (a[i].y>a[i].x) x+=a[i].z;else break;
sort(a+1,a+n+1,cmp);
for (ll i=x/m-2;i<=x/m+2;i++) check(i);
sort(a+1,a+n+1);
x=0;for (int i=1;i<=n;i++) if (a[i].y>=a[i].x) x+=a[i].z;else break;
sort(a+1,a+n+1,cmp);
for (ll i=x/m-2;i<=x/m+2;i++) check(i);
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
D:注意到在某一天卖出再买进对答案是没有影响的。于是维护一个小根堆,每次取出堆顶与当前天价格比较,若能赚钱则计入答案并将堆顶弹出,相当于在堆顶那天买进然后在当前天卖出,然后将当前天价格入堆。我们还需要支持一个反悔操作,即更换买进天的匹配对象,容易发现把当前天价格再入一次堆就可以了。大约是在模拟费用流。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N];
ll ans=0;
priority_queue<int,vector<int>,greater<int> > q;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("d.in","r",stdin);
freopen("d.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++)
{
if (!q.empty()&&q.top()<a[i])
{
ans+=a[i]-q.top();
int x=q.top();q.pop();
q.push(a[i]);
}
q.push(a[i]);
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
C:期望考虑倒推,但难以计算重置带来的影响。于是考虑先固定住重置的作用,即二分答案,这样重置之后就相当于可以用等于答案的时间直接通关。然后就可以dp了,即设f[i][j]为i~n关要用至多j时间通关的话最少要花多久。最后得到f[1][m],判断其和二分出的答案的大小,若比其大说明一开始就得重置,这显然说明二分出来的答案小了;反之亦然。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
#define inf ((double)100000000000)
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N],b[N],p[N];
double f[N][N*N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read(),b[i]=read(),p[i]=read();
double l=0,r=inf,ans;
for (int _=1;_<=100;_++)
{
double mid=(l+r)/2;
for (int i=n;i>=1;i--)
for (int j=0;j<=m;j++)
{
f[i][j]=0.01*((a[i]+(j>=a[i]?f[i+1][j-a[i]]:mid))*p[i]+(b[i]+(j>=b[i]?f[i+1][j-b[i]]:mid))*(100-p[i]));
if (i>1) f[i][j]=min(f[i][j],mid);
}
if (f[1][m]>mid) ans=mid,l=mid;else r=mid;
}
printf("%.11f",ans);
return 0;
//NOTICE LONG LONG!!!!!
}
Codeforces Round #437 Div. 1的更多相关文章
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
Problem A Between the Offices 水题,水一水. #include<bits/stdc++.h> using namespace std; int n; ]; i ...
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E
题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同: 题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相 ...
- 【Codeforces Round #437 (Div. 2) A】Between the Offices
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...
- 【Codeforces Round #437 (Div. 2) B】Save the problem!
[链接]h在这里写链接 [题意] 给你一个金额N,和硬币的类型总数M; (完全背包),然后问你组成N的方案数. 使得,用这些硬币组成价值为N的金额的方案数为A; 现在A ...
- 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza
[链接]h在这里写链接 [题意] 给你参赛者的数量以及一个整数S表示每块披萨的片数. 每个参数者有3个参数,si,ai,bi; 表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- 显式与隐式(ExplicitAndImplicit)
显式与隐式(Explicit And Implicit) 1.概念 1.1 显式 实现的单词Explicit意思是清楚的.明确的.详述的.所以,显式的“显”是指明显且清楚的实现,相对于接口来说,就是明 ...
- COMCMS v0.9 版本发布,带前后端的一个响应式企业站
前言:踏入十二月,人生也即将进入下一个阶段. 最近忙于其他,代码也是偶尔更新.目前算是0.9的版本,就是基本上可以完成一个简单的企业站/博客的功能. 主要特点:前台完整演示:文章.产品.留言.界面响应 ...
- python--Numpy and Pandas 笔记01
博客地址:http://www.cnblogs.com/yudanqu/ 1 import numpy as np import pandas as pd from pandas import Ser ...
- 07 YAPI/基础设施 - DevOps之路
07 YAPI/基础设施 - DevOps之路 文章Github地址,欢迎start:https://github.com/li-keli/DevOps-WiKi 简介 YApi 是一个可本地部署的. ...
- 简单的将Excel数据同步到SqlServer数据库中
1.创建一个WinForm程序,添加一个Button控件 2.Button事件 private void button1_Click(object sender, EventArgs e) { Sys ...
- MySQL 日期类型函数及使用
1 MySQL 数据库中有五种与日期时间有关的数据类型,各种日期数据类型所占空间如下图所示: 2 datetime 与 date datetime 占用8字节,是占用空间最多的一种日期格式.它显示日期 ...
- Oracle通过ROWID删除表中重复记录
-- 1 通过ROWID删除T1表里重复的记录 SELECT ROWID,A,B--DELETE FROM T1WHERE ROWID IN ( SELECT RD FROM ( ...
- [转帖]windows7/windows NT介绍
windows7/windows NT介绍 原文应该是IT168发布的 但是一直没找到 感觉看了之后 明白了很多 技术都是互相融合的 没有严格意义上的对立直说. Windows 7/Windows ...
- Django--CRM--菜单展示, 删除合并, 权限展示
一 . 菜单展示 二 . 合并删除 我们可以把所有的删除都合并成一个函数这样就会减少很多的代码. 思路: 在url里面需要传两个参数,一个是要删的id 一个是名字 三 .权限展示 我们要实现两个功能 ...
- DNS 到底怎么工作的? (How does dns work?)
其实这个问题每次看的时候都觉得很明白,但是很久之后就忘记了,所以这次准备记录下来.深入到这个过程的各个细节之中,以后多看看. Step 1 请求缓存信息: 当你在开始访问一个 www.baidu.co ...