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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- Golang---序列化和反序列化
为什么要序列化和反序列化 我们的数据对象要在网络中传输或保存到文件,就需要对其编码和解码动作,目前存在很多编码格式:json, XML, Gob, Google Protocol Buffer 等, ...
- PAT Advanced 1003 Emergency (25) [Dijkstra算法]
题目 As an emergency rescue team leader of a city, you are given a special map of your country. The ma ...
- 关于indexOf的用法
var fullTaskName = this.form.taskName; var index=fullTaskName.lastIndexOf("-"); ...
- 深入浅出Python装饰器
1.前言 装饰器是Python的特有的语法,刚接触装饰器的同学可能会觉得装饰器很难理解,装饰器的功能也可以不用装饰器实现,但是装饰器无疑是提高你Python代码质量的利器(尤其是使用在一些具有重复功能 ...
- Sequence Models Week 3 Trigger word detection
Trigger Word Detection Welcome to the final programming assignment of this specialization! In this w ...
- POJ 1260:Pearls 珍珠DP
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7947 Accepted: 3949 Descriptio ...
- 调用约定__stdcall / __cdecl
__cdecl与__stdcall这两种调用约定之间的主要差别在于由谁来执行对参数的清理工作. 如果是__cdecl,那么主调函数将负责执行清理工作,如果是__stdcall那被调函数将负责执行清理. ...
- python安装wordcloud、jieba,pyecharts
1.安装wordcloud: 适用于无法使用pip install wordcloud安装的情况: 据python和windows 版本 到https://www.lfd.uci.edu/~gohlk ...
- h5-动画基本介绍
1.介绍 *{ ; ; } div{ width: 200px; height: 200px; background-color: #5aff61; /*添加动画效果*/ /*1.animation- ...
- python中的单元测试模块unittest
unittest的属性: 该文以思维导图的形式描述unittest的重要属性. 其中前四个是unittest最核心的三个属性. testcase:测试用例: testsuite:测试套件,多个测试用例 ...