Codeforces Round #419 Div. 1
A:暴力枚举第一列加多少次,显然这样能确定一种方案。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
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][N],b[N][N],ans[1000000][2],u,v,qwq[1000000][2];
ll qaq;
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++)
for (int j=1;j<=m;j++)
qaq+=a[i][j]=read();
u=1000000;
for (int i=0;i<=500;i++)
{
bool flag=0;
for (int j=1;j<=n;j++) if (a[j][1]<i) {flag=1;break;}
if (flag) break;
memcpy(b,a,sizeof(b));v=0;
for (int j=1;j<=i;j++) v++,qwq[v][0]=1,qwq[v][1]=1;
for (int j=1;j<=n;j++) b[j][1]-=i;
for (int j=1;j<=n;j++)
{
for (int x=1;x<=b[j][1];x++) v++,qwq[v][0]=0,qwq[v][1]=j;
for (int x=2;x<=m;x++)
b[j][x]-=b[j][1];
b[j][1]=0;
}
flag=0;
for (int j=1;j<=n;j++)
for (int x=1;x<=m;x++)
if (b[j][x]<0) {flag=1;break;}
if (!flag)
{
for (int j=2;j<=m;j++)
{
int y=510;
for (int x=1;x<=n;x++)
y=min(y,b[x][j]);
for (int x=1;x<=y;x++) v++,qwq[v][0]=1,qwq[v][1]=j;
for (int x=1;x<=n;x++)
b[x][j]-=y;
flag=0;
for (int x=1;x<=n;x++)
if (b[x][j]) {flag=1;break;}
if (flag) break;
}
if (!flag&&v<u)
{
u=v;for (int j=1;j<=u;j++) ans[j][0]=qwq[j][0],ans[j][1]=qwq[j][1];
}
}
}
if (u==1000000) {cout<<-1;return 0;}
cout<<u<<endl;
for (int i=1;i<=u;i++)
{
if (ans[i][0]==0) printf("row ");
else printf("col ");
printf("%d\n",ans[i][1]);
}
return 0;
//NOTICE LONG LONG!!!!!
}
B:显然每个数的贡献与组合数有关,找找规律发现讨论一下n%4的几种情况就行了。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
#define P 1000000007
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],b[N],fac[N],inv[N],ans;
int C(int n,int m){if (n<0||m<0||m>n) return 0;return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) b[i]=a[i]=read();
fac[0]=fac[1]=1;for (int i=2;i<=n;i++)fac[i]=1ll*fac[i-1]*i%P;
inv[0]=inv[1]=1;for (int i=2;i<=n;i++) inv[i]=P-1ll*(P/i)*inv[P%i]%P;
for (int i=2;i<=n;i++) inv[i]=1ll*inv[i]*inv[i-1]%P;
if (n%4==1)
{
for (int i=1;i<=n;i++)
if (i&1) ans=(ans+1ll*a[i]*C(n/2,i/2))%P;
}
else if (n%4==3)
{
for (int i=1;i<=n;i++)
if (i&1) ans=(ans+1ll*a[i]*(C((n-3)/2,i/2)-C((n-3)/2,i/2-1)+P))%P;
else ans=(ans+2ll*a[i]*C((n-3)/2,i/2-1))%P;
}
else
{
for (int i=1;i<=n;i++)
if ((i&1)||n%4==2) ans=(ans+1ll*a[i]*C(n/2-1,(i-1)/2))%P;
else ans=(ans-1ll*a[i]*C(n/2-1,i/2-1)%P+P)%P;
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
C:显然依赖关系形成一棵树。设f[i][j]为i子树选j个的最小代价,其中根必须使用优惠券;g[i][j]为i子树选j个的最小代价,不能使用优惠券。直接背包即可,众所周知复杂度O(n2)。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 5010
#define inf 1010000000
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,p[N],f[N][N],s[N][N],size[N],t,c[N],d[N];
struct data2{int to,nxt;
}edge[N];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void dfs(int k)
{
size[k]=1;s[k][1]=c[k];f[k][1]=d[k];f[k][0]=inf;
for (int i=p[k];i;i=edge[i].nxt)
{
dfs(edge[i].to);
for (int j=size[k]+1;j<=size[k]+size[edge[i].to];j++) f[k][j]=s[k][j]=inf;
for (int j=size[k];j>=0;j--)
for (int x=size[edge[i].to];x>=0;x--)
s[k][j+x]=min(s[k][j+x],s[k][j]+s[edge[i].to][x]),
f[k][j+x]=min(f[k][j+x],f[k][j]+min(s[edge[i].to][x],f[edge[i].to][x]));
size[k]+=size[edge[i].to];
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++)
{
c[i]=read(),d[i]=c[i]-read();
if (i>1) addedge(read(),i);
}
dfs(1);
int ans=0;
for (int i=0;i<=n;i++) if (f[1][i]<=m||s[1][i]<=m) ans=i;
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
D:枚举第一维,剩下两维看成一个平面,考虑每张牌对答案的限制。容易发现根据第一维是大还是小分成两类,分别将答案所对应的点限制在一块矩形区域(或两个矩形的并),且对于同一张牌,后者对应的区域包含前者。现在要动态维护这些区域的交的面积。
考虑改为求其补集的并。注意到这些矩形底部都在坐标轴上。那么相当于要支持区间取max区间求和。并且可以注意到其矩形并构成下降阶梯状。于是建棵线段树,修改时线段树上二分时找到边界,区间取max改为区间覆盖即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cassert>
using namespace std;
#define ll long long
#define N 500010
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,B,C,L[N<<2],R[N<<2],lazy[N<<2],mx[N<<2];
ll ans,tree[N<<2];
struct data
{
int x,y,z;
bool operator <(const data&a) const
{
return x<a.x;
}
}a[N];
void up(int k)
{
tree[k]=tree[k<<1]+tree[k<<1|1];
mx[k]=max(mx[k<<1],mx[k<<1|1]);
}
void update(int k,int x)
{
tree[k]=1ll*(R[k]-L[k]+1)*x;
lazy[k]=mx[k]=x;
}
void down(int k)
{
update(k<<1,lazy[k]);
update(k<<1|1,lazy[k]);
lazy[k]=0;
}
void build(int k,int l,int r)
{
L[k]=l,R[k]=r;
if (l==r) return;
int mid=l+r>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
}
int find(int k,int x)
{
if (L[k]==R[k]) return L[k]+(mx[k]>=x);
if (lazy[k]) down(k);
if (mx[k<<1|1]>=x) return find(k<<1|1,x);
else return find(k<<1,x);
}//��һ��<x��λ��
void cover(int k,int l,int r,int x)
{
if (L[k]==l&&R[k]==r) {update(k,x);return;}
if (lazy[k]) down(k);
int mid=L[k]+R[k]>>1;
if (r<=mid) cover(k<<1,l,r,x);
else if (l>mid) cover(k<<1|1,l,r,x);
else cover(k<<1,l,mid,x),cover(k<<1|1,mid+1,r,x);
up(k);
}
void modify(int x,int y)
{
int u=find(1,y);
if (u<=x) cover(1,u,x,y);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),A=read(),B=read(),C=read();
for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read(),a[i].z=read();
sort(a+1,a+n+1);
build(1,1,B+1);
for (int i=1;i<=n;i++) modify(a[i].y,a[i].z);
int x=n+1;
for (int i=A;i>=1;i--)
{
while (a[x-1].x>=i)
{
x--;
modify(B,a[x].z);
modify(a[x].y,C);
}
ans+=1ll*B*C-tree[1];
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
Codeforces Round #419 Div. 1的更多相关文章
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
- Codeforces Round #419 (Div. 2)
1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...
- Codeforces Round #419 (Div. 2) ABC
python 2.7,用来熟悉Python 由于都是智障题,所以我也不讲述题意和题解,直接贴代码了-- A import sys h,m = map(int,raw_input().split(&qu ...
- Codeforces Round #419 (Div. 2) C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Codeforces Round #419 (Div. 2)(B)差分数组
传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9721160.html 题意: Karen有n个关于煮咖啡的食谱,每个食谱都有个煮咖啡的最适 ...
- Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
随机推荐
- Sequelize 连接微软云数据库 SQL Azure
function getConnection(){ var sequelize=new Sequelize("DBName","sa","000000 ...
- vue内置组件 transition 和 keep-alive 使用
1.transition name - string,用于自动生成 CSS 过渡类名.例如:name: 'fade' 将自动拓展为.fade-enter,.fade-enter-active等.默认类 ...
- python中换行,'\r','\n'及'、'\r\n'
'\r'的本意是回到行首,'\n'的本意是换行. 所以回车相当于做的是'\r\n'或者'\n\r'.'\r'就是换行并回行首, '\n'就是换行并回行首,用'\r\n'表示换行并回行首. window ...
- Vue-router路由使用,单页面的实现
1.安装路由系统 NPM npm install vue-router 2.在main.js中进入引用 import VueRouter from 'vue-router' 3.创建三个空的组件: V ...
- MySQL 通过多个示例学习索引
最近在准备面试,关于索引这一块,发现很多以前忽略的点,这里好好整理一下 首先为什么要建立索引 一本书,有章.节.段.行这种单位. 如果现在需要找一个内容:第9章>第2节>第3段>第4 ...
- Visual Studio 2010 Shortcuts
Uploaded by ProNotion, updated on 11/28/2013 by jmb Platform: Windows/ English PDF Print Hide ...
- IdentityServer4【Topic】之StartUp中的配置
Startup 身份服务器是中间件和服务的组合.所有的配置都是在启动类中完成的. Configuring services 通过调用如下代码在DI(dependency inject,依赖注入)中添加 ...
- composer 自动加载类 通过psr
项目地址 git@github.com:brady-wang/composer.git "autoload":{ "classmap":[ "Lib ...
- day 7-11 初识MySQL数据库及安装密码设置破解
一. 什么是数据库 之前所学,数据要永久保存,比如用户注册的用户信息,都是保存于文件中,而文件只能存在于某一台机器上. 如果我们不考虑从文件中读取数据的效率问题,并且假设我们的程序所有的组件都运行在一 ...
- 跨站请求伪造和cookie伪造
CSRF(Cross-site request forgery跨站请求伪造,也被称成为“one click attack”或者session riding,通常缩写为CSRF或者XSRF,是一种对网站 ...