Codeforces Round #559(Div.1)
A
签到贪心题,特判了n=1或m=1的情况才发现2<=n,m<=1e5
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+;
int n,m;
ll ans,a[N],b[N];
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%I64d",&a[i]);
for(int i=;i<=m;i++)scanf("%I64d",&b[i]);
sort(a+,a+n+);
sort(b+,b+m+);
if(a[n]>b[]){puts("-1");return ;}
if(n==)
{
if(a[]<b[]){puts("-1");return ;}
for(int i=;i<=m;i++)ans+=b[i];
cout<<ans;return ;
}
if(m==)
{
if(a[n]<b[]){puts("-1");return ;}
for(int i=;i<=n;i++)ans+=a[i];
cout<<ans;return ;
}
if(a[n]==b[])
{
for(int i=;i<=m;i++)ans+=b[i];
for(int i=;i<n;i++)ans+=a[i]*m;
cout<<ans;return ;
}
ans=a[n];for(int i=;i<=m;i++)ans+=b[i];
ans+=b[]+a[n-]*(m-);
for(int i=n-;i;i--)ans+=a[i]*m;
cout<<ans;
}
B
结论题,根本看不出来,k=1特判掉,其余构造方案是这样的:让循环节长度为(n-k)/2+1,然后为10…0即可,推一下发现是正确的。
#include<bits/stdc++.h>
using namespace std;
int n,k,l;
int main()
{
cin>>n>>k;
if(k==)
{
for(int i=;i<n;i++)cout<<;cout<<;
return ;
}
l=(n-k)/+;
for(int i=;i<n;i++)cout<<!(i%l);
}
C
其实每个nxt不为1位置就是两个限制:1、a[nxt]>a[i]。2、a[i+1...nxt-1]<a[i]。然后根据这个建立拓扑图,进行拓扑排序即可。不过由于边数是O(n2)的,对于第二种边考虑线段树优化建图,实际上也不需要线段树优化建边,写普通的线段树即可。把大数连边向小数,然后修改时度数直接线段树-1减就行了。减的过程中,线段树维护的是区间度数最小值,发现最小值为0时,把其加入队列,并把该位置最小值赋值为无穷大即可。
#include<bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int N=5e5+;
int n,m,sr[N],vis[N],ans[N],lazy[N<<],mn[N<<];
vector<int>G[N];
queue<int>q;
void build(int l,int r,int rt)
{
lazy[rt]=mn[rt]=;
if(l==r)return;
int mid=l+r>>;
build(lson),build(rson);
}
void pushdown(int rt)
{
lazy[rt<<]+=lazy[rt],mn[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt],mn[rt<<|]+=lazy[rt];
lazy[rt]=;
}
void modify(int l,int r,int rt)
{
if(l==r){mn[rt]=1e9,q.push(l);return;}
pushdown(rt);
int mid=l+r>>;
if(!mn[rt<<])modify(lson);
if(!mn[rt<<|])modify(rson);
mn[rt]=min(mn[rt<<],mn[rt<<|]);
}
void update(int L,int R,int v,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
lazy[rt]+=v,mn[rt]+=v;
if(!mn[rt])modify(l,r,rt);
return;
}
pushdown(rt);
int mid=l+r>>;
if(L<=mid)update(L,R,v,lson);
if(R>mid)update(L,R,v,rson);
mn[rt]=min(mn[rt<<],mn[rt<<|]);
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)G[i].clear(),vis[i]=;
build(,n,);
for(int i=;i<=n;i++)
{
sr[i]=-;
int x;scanf("%d",&x);
if(x==-)continue;
if(x<=n)G[x].push_back(i),update(i,i,,,n,);
if(x>i+)sr[i]=x-,update(i+,x-,,,n,);
}
while(!q.empty())q.pop();
if(!mn[])modify(,n,);
m=n;
while(!q.empty())
{
int u=q.front();q.pop();
ans[u]=m--;
for(int i=;i<G[u].size();i++)update(G[u][i],G[u][i],-,,n,);
if(sr[u]!=-)update(u+,sr[u],-,,n,);
}
if(m)puts("-1");
else{
for(int i=;i<=n;i++)printf("%d ",ans[i]);
puts("");
}
}
}
D
首先把所有点像求解凸包一样,按照横坐标排序,横坐标相同按纵坐标排序。然后可以贪心地考虑。首先第一个点必须在凸包上,对于这样的点,其对于L/R都有选择的机会,然后选择后,第二个点从n-1个点中选择最外侧的点,满足其余的n-2个点在a[2]-a[1]的左/右侧,这个计算叉积即可。然后接下来的求解方法是一样的,反复如此操作即可找到符合条件的排列,因此没有puts("-1")的情况。复杂度为常数较大(因为涉及实数运算)的O(n2)。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
struct point{
ll x,y;int id;
point(){x=y=;}
point(ll a,ll b){x=a,y=b;}
point operator-(const point&t)const{return point(x-t.x,y-t.y);}
bool operator<(const point&t)const{return x==t.x?y<t.y:x<t.x;}
}a[N];
int n,m,vis[N],ans[N];
char str[N];
int sign(ll x){return x==?:(x>?:-);}
bool cmp(point a,point b){return a.id<b.id;}
ll cross(point a,point b){return a.x*b.y-a.y*b.x;}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%lld%lld",&a[i].x,&a[i].y),a[i].id=i;
sort(a+,a+n+);
ans[++m]=a[].id,vis[a[].id]=;
scanf("%s",str+);
sort(a+,a+n+,cmp);
for(int i=;i<=n-;i++)
{
int k=,flag=str[i]=='L'?:-;
for(int j=;j<=n;j++)
if(!vis[j]&&(!k||sign(cross(a[k]-a[ans[i]],a[j]-a[k]))!=flag))k=j;
ans[++m]=k,vis[k]=;
}
for(int i=;i<=n;i++)if(!vis[i])ans[++m]=i;
for(int i=;i<=n;i++)printf("%d ",ans[i]);
}
EF
咕了。
result:rank251 rating-=41。这场人怎么这么少?都去打CTS了?
Codeforces Round #559(Div.1)的更多相关文章
- 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”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 简单的说一下react路由(逆战班)
现代前端大多数都是SPA(单页面程序),也就是只有一个HTML页面的应用程序,因为它的用户体验更好,对服务器压力更小,所以更受欢迎,为了有效的使用单个页面来管理原来多页面的功能,前端路由应运而生. 前 ...
- Java基础之反射、注解、代理
反射 笔者对反射的理解就是解剖class文件,来进行一系列操作. Class类 获取Class类实例的三种方式: 类名.class 对象.getClass() static Class forName ...
- Palette 的使用
Palette有什么用? Palette主要功能就是可以从图片中提取各种与颜色有关的元素.通过使用 Palette ,我们可以很轻松的实现界面风格的统一. Palette的使用很简单,首先你可以从gi ...
- HDU 5311:Hidden String
Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- continue break
#!/bin/bashfor i in `seq 10`do if ((i%3==0)) thenecho !! continue fiecho $idone 结果: ...
- java课程之团队开发冲刺阶段1.8
一.总结昨天进度 1.实现预装sqlite数据库,将数据库放在app的assets目录下,该目录在打包的时候不会压缩,所以数据库文件可以在安装之后继续使用,然后APP安装之后检测外部存储空间是否有这个 ...
- bootstrap 网格
实现原理 网格系统的实现原理非常简单,仅仅是通过定义容器大小,平分12份(也有平分成24份或32份,但12份是最常见的),再调整内外边距,最后结合媒体查询,就制作出了强大的响应式网格系统.Bootst ...
- PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]
题目 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level ...
- B - Given Length and Sum of Digits... CodeForces - 489C (贪心)
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and th ...
- Ctrl +c 脚本中
#!/bin/bashsar -n DEV 1 111111111111111 >>1.txt & #实时网卡流量数据 sleep 3 && kill -2 ...