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)的更多相关文章

  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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. Linux - 安装 dotnet core 环境

    Linux -  安装 dotnet core 环境 系统环境:CentOS7 官方安装指导 https://www.microsoft.com/net/learn/get-started/linux ...

  2. windows 2008R2 搭建web实现https访问

    一.安装服务. 二.IIS创建证书申请. 三.ca颁发证书 三.创建网站. 创建一个新建文件夹,并在文件夹中创建一个txt文件. 把新建文本文档.txt重命名为index.html 完成证书申请(导入 ...

  3. vSphere Replication5.5安装

    vSphere Replication5.5概述 VMware vSphere Replication简称VR是 VMwarevCenter Server 的扩展,提供基于管理程序的虚拟机复制和恢复功 ...

  4. Python String startswith() Method

    一,摘自官方API  https://docs.python.org/3/library/stdtypes.html#methods str.startswith(prefix[, start[, e ...

  5. nginx log 切割

    /logs/nginx/*/*access.log { daily rotate 30 missingok dateext #compress notifempty sharedscripts pos ...

  6. CAD快捷键大全

  7. Thread--synchronized不能被继承?!?!!!

    参考:http://bbs.csdn.net/topics/380248188 其实真相是这样的,“synchronized不能被继承”,这句话有2种不同意思,一种是比较正常的.很容易让人想到的意思: ...

  8. JavaScript—飞机大战2版

    前面的思路对了  BUG 出在了计时器和没有加判断页面是否存在元素 <!DOCTYPE html> <html lang="en"> <head> ...

  9. 总结一些常用的训练 GANs 的方法

    众所周知,GANs 的训练尤其困难,笔者自从跳入了 GANs 这个领域(坑),就一直在跟如何训练 GANs 做「对抗训练」,受启发于 ganhacks,并结合自己的经验记录总结了一些常用的训练 GAN ...

  10. IDEA忽略文件,防止git提交不想提交的文件

    IDEA忽略文件,防止git提交不想提交的文件 方法一(只对没有add到仓库的文件有效): 方法二(只对没有add到仓库的文件有效): 在IDEA中安装.ignore插件.创建好了之后: 安装.git ...