Codeforces Round #433 Div. 1
A:显然从大到小排序后贪心放在第一个能放的位置即可。并查集维护。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
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,m,a[N],b[N],id[N],fa[N<<1];
ll ans;
bool cmp(const int&x,const int&y)
{
return a[x]>a[y];
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
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++) id[i]=i,a[i]=read();
sort(id+1,id+n+1,cmp);
for (int i=m+1;i<=m+n+1;i++) fa[i]=i;
for (int i=1;i<=n;i++)
{
b[id[i]]=find(max(m+1,id[i]));
ans+=1ll*a[id[i]]*(b[id[i]]-id[i]);
fa[b[id[i]]]=find(b[id[i]]+1);
}
cout<<ans<<endl;
for (int i=1;i<=n;i++) printf("%d ",b[i]);
return 0;
//NOTICE LONG LONG!!!!!
}
B:对前后缀处理出答案,two pointers即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
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,k;
ll pre[N],suf[N],cost[N];
bool flag[N];
struct data
{
int t,x,y,c;
bool operator <(const data&a) const
{
return t<a.t;
}
}a[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read(),k=read();
for (int i=1;i<=m;i++)
{
int t=read(),x=read(),y=read(),c=read();
a[i].t=t,a[i].x=x,a[i].y=y,a[i].c=c;
}
sort(a+1,a+m+1);
memset(pre,42,sizeof(pre));int cnt=0;
memset(cost,42,sizeof(cost));
memset(flag,0,sizeof(flag));
for (int i=1;i<=m;i++)
{
pre[i]=pre[i-1];
if (a[i].y==0)
{
if (!flag[a[i].x])
{
cnt++;
cost[a[i].x]=a[i].c;
flag[a[i].x]=1;
if (cnt==n)
{
pre[i]=0;
for (int j=1;j<=n;j++) pre[i]+=cost[j];
}
}
else
if (a[i].c<cost[a[i].x])
{
if (cnt==n) pre[i]-=cost[a[i].x]-a[i].c;
cost[a[i].x]=a[i].c;
}
}
}
memset(suf,42,sizeof(suf));cnt=0;
memset(cost,42,sizeof(cost));
memset(flag,0,sizeof(flag));
for (int i=m;i>=1;i--)
{
suf[i]=suf[i+1];
if (a[i].x==0)
{
if (!flag[a[i].y])
{
cnt++;flag[a[i].y]=1;
cost[a[i].y]=a[i].c;
if (cnt==n)
{
suf[i]=0;
for (int j=1;j<=n;j++) suf[i]+=cost[j];
}
}
else
if (a[i].c<cost[a[i].y])
{
if (cnt==n) suf[i]-=cost[a[i].y]-a[i].c;
cost[a[i].y]=a[i].c;
}
}
}
int x=0;ll ans=pre[0];
for (int i=1;i<=m;i++)
{
while (a[i].t-a[x+1].t>k) x++;
if (x) ans=min(ans,pre[x]+suf[i]);
}
if (ans==pre[0]) cout<<-1;
else cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
C:根据查询矩形边界将平面分成九块,讨论两端点位置即可,主席树支持查询矩形内点的个数。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
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,q,a[N],root[N],cnt;
struct data{int l,r,x;
}tree[N<<6];
void ins(int &k,int l,int r,int x)
{
tree[++cnt]=tree[k];k=cnt;tree[k].x++;
if (l==r) return;
int mid=l+r>>1;
if (x<=mid) ins(tree[k].l,l,mid,x);
else ins(tree[k].r,mid+1,r,x);
}
int Query(int x,int y,int l,int r,int p,int q)
{
if (!y) return 0;
if (l==p&&r==q) return tree[y].x-tree[x].x;
int mid=l+r>>1;
if (q<=mid) return Query(tree[x].l,tree[y].l,l,mid,p,q);
else if (p>mid) return Query(tree[x].r,tree[y].r,mid+1,r,p,q);
else return Query(tree[x].l,tree[y].l,l,mid,p,mid)+Query(tree[x].r,tree[y].r,mid+1,r,mid+1,q);
}
int query(int l,int r,int x,int y)
{
if (l>r||x>y) return 0;
return Query(root[l-1],root[r],1,n,x,y);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),q=read();
for (int i=1;i<=n;i++)
{
root[i]=root[i-1];
a[i]=read();
ins(root[i],1,n,a[i]);
}
for (int _=1;_<=q;_++)
{
int l=read(),d=read(),r=read(),u=read();
int x=query(l,r,d,u),f=query(l,r,1,d-1),g=query(l,r,u+1,n);
int v=query(1,l-1,d,n),w=query(1,l-1,1,u);
ll ans=0;
ans+=1ll*f*v;
ans+=1ll*g*w;
ans+=1ll*x*(l-1);
ans+=1ll*(r-l+1)*(r-l)/2;
ans-=1ll*f*(f-1)/2;
ans-=1ll*g*(g-1)/2;
ans+=1ll*query(r+1,n,1,d-1)*(x+g+v);
ans+=1ll*query(r+1,n,u+1,n)*(x+f+w);
ans+=1ll*query(r+1,n,d,u)*r;
printf("%I64d\n",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}
D:显然每天要么不用优惠,要么就尽量用优惠。并且显然如果某天可以优惠到免费,使用优惠不会更劣。所以直接f[i][j]表示前i天剩余优惠为j时的最小代价,瞎转移即可,由上面的性质j不会超过21。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
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],f[N][32];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read()/100;
memset(f,42,sizeof(f));f[0][0]=0;
for (int i=1;i<=n;i++)
{
for (int j=0;j<=30;j++)
if (j>=a[i]/10) f[i][j]=f[i-1][j-a[i]/10]+a[i];
for (int j=0;j<=30-a[i];j++)
f[i][j]=min(f[i][j],f[i-1][j+a[i]]);
for (int j=0;j<=a[i];j++) f[i][0]=min(f[i][0],f[i-1][j]+a[i]-j);
}
int ans=1000000000;
for (int i=0;i<=30;i++) ans=min(ans,f[n][i]);
cout<<100ll*ans;
return 0;
//NOTICE LONG LONG!!!!!
}
Codeforces Round #433 Div. 1的更多相关文章
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...
- codeforces 853b//Jury Meeting// Codeforces Round #433 (Div. 1)
题意:几个人要去一个城市k天,现给出各航班的日期和花费,让这n个人能相会k天的最小花费? 用数组arr1[i]记录在第i天人到齐的最小花费.arr2[i]记录第i天之后才有人开始走的最小花费.然后取a ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)
D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned tha ...
- 【Codeforces Round #433 (Div. 1) B】Jury Meeting
[链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...
随机推荐
- 使用后台线程BackgroundWorker处理任务的总结
在一些耗时的操作过程中,在长时间运行时可能会导致用户界面 (UI) 处于停止响应状态,用户在这操作期间无法进行其他的操作,为了不使UI层处于停止响应状态,我们倾向推荐用户使用BackgroundWor ...
- python 可调用对象之类实例
可调用对象,即任何可以通过函数操作符()来调用的对象. python可调用对象大致可以分为4类: 1.函数 python中有三种函数:内建函数(BIFs).用户自定义函数(UDF).lambda表达式 ...
- MySQL之索引原理
--------------------------------------------------------------------------------堕落的状态,无疑是慢性自杀.想想自己为什 ...
- Java 自动装箱与拆箱(Autoboxing and unboxing)
什么是自动装箱拆箱 基本数据类型的自动装箱(autoboxing).拆箱(unboxing)是自J2SE 5.0开始提供的功能. 一般我们要创建一个类的对象实例的时候,我们会这样: Class a = ...
- UVA 10791 -唯一分解定理的应用
#include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> ...
- PAT L2-014 列车调度
https://pintia.cn/problem-sets/994805046380707840/problems/994805063166312448 火车站的列车调度铁轨的结构如下图所示. 两端 ...
- 微信开发 提示 Redirect_uri(错误10003)
情景: 搭建完成一个网站,使用微信打开链接地址,结果报错1003 完整的错误信息: 出现这种情况一般有两种原因: 1.没有配置网页授权 我们可以根据微信的开发者文档http://mp.weixin. ...
- js原生实现div渐入渐出
jq对渐入渐出进行封装,简单的使用连个方法就可以实现.fadeIn(),fadeOut();如果我们界面没有使用jq那么原生怎么实现呢? 我们讲解一下,这个原理.当我们要实现渐入的时候,首先是让隐藏的 ...
- 逻辑斯特回归tensorflow实现
calss #!/usr/bin/python2.7 #coding:utf-8 from __future__ import print_function import tensorflow as ...
- Git SSH公钥配置
https://www.cnblogs.com/smuxiaolei/p/7484678.html https://blog.csdn.net/weixin_42063071/article/deta ...