A.只要考虑分成一个串的情况就可以了。

#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
if(a[]% && a[n]% && n%) cout << "Yes" << endl;
else cout << "No" << endl;
return ;
}

B.1.若所有点在一条直线,则no。

2.若a[1]单独一组,剩余点在一条直线,则yes。

3.枚举a[1]和后面点组成的直线,判断是否能把点分成两组。

#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
int t = a[]-a[];
int ok = ;
for(int i = ;i <= n;i++)
{
if(a[i]-a[i-] != t) ok = ;
}
if(!ok)
{
if(a[]-a[] == t) cout << "No" << endl;
else cout << "Yes" << endl;
return ;
}
ok = ;
for(int i = ;i <= n;i++)
{
double t = 1.0*(a[i]-a[])/(i-);
vector<int> v;
for(int j = ;j <= n;j++)
{
if(abs(1.0*(a[j]-a[])/(j-)-t) > 1e-) v.push_back(j);
}
int flag = ;
for(int j = ;j < v.size();j++)
{
if(abs(1.0*(a[v[j]]-a[v[]])/(v[j]-v[])-t) > 1e-) flag = ;
}
if(flag) ok = ;
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
return ;
}

C.首先,每个字母相互独立。对于每个字母,最优的方案是一个一个加,打个表,每次加个最大可行量。注意0的特殊情况。

#include<bits/stdc++.h>
using namespace std; int n,x[];
string ans = "z"; int main()
{
ios::sync_with_stdio();
x[] = ;
for(int i = ;i <= ;i++) x[i] = x[i-]+i-;
cin >> n;
for(char c = 'a';c <= 'z';c++)
{
if(n == ) break;
int t = ;
while(x[t] > n) t--;
n -= x[t];
while(t--) ans.append(,c);
}
cout << ans << endl;
return ;
}

D.分成两组,按照g-t排序,这个顺序保证相遇顺序。

之后双指针模拟,遇到连续的几个相同时,画个图便知道那个点从哪里出了。

#include<bits/stdc++.h>
using namespace std; int n,w,h,tx[],ty[],ansx[],ansy[];
struct xx
{
int x,t,id;
friend bool operator<(xx a,xx b)
{
if(a.x-a.t != b.x-b.t) return a.x-a.t < b.x-b.t;
return a.x < b.x;
}
}a[],b[]; int main()
{
ios::sync_with_stdio();
cin >> n >> w >> h;
int cnt1 = ,cnt2 = ;
for(int i = ;i <= n;i++)
{
int x,y,t;
cin >> x >> y >> t;
if(x == )
{
a[++cnt1].x = y;
a[cnt1].t = t;
a[cnt1].id = i;
tx[i] = y;
ty[i] = h;
}
else
{
b[++cnt2].x = y;
b[cnt2].t = t;
b[cnt2].id = i;
tx[i] = w;
ty[i] = y;
}
}
sort(a+,a++cnt1);
sort(b+,b++cnt2);
int now1 = ,now2 = ;
while(now1 <= cnt1 && now2 <= cnt2)
{
if(a[now1].x-a[now1].t == b[now2].x-b[now2].t)
{
int t1 = now1+,t2 = now2+;
while(t1 <= cnt1 && a[now1].x-a[now1].t == a[t1].x-a[t1].t) t1++;
while(t2 <= cnt2 && b[now2].x-b[now2].t == b[t2].x-b[t2].t) t2++;
vector<int> v1,v2;
for(int i = now1;i < t1;i++) v1.push_back(a[i].id);
for(int i = t2-;i >= now2;i--) v1.push_back(b[i].id);
for(int i = t2-;i >= now2;i--) v2.push_back(b[i].id);
for(int i = now1;i < t1;i++) v2.push_back(a[i].id);
for(int i = ;i < v1.size();i++)
{
ansx[v2[i]] = tx[v1[i]];
ansy[v2[i]] = ty[v1[i]];
}
now1 = t1;
now2 = t2;
}
else if(a[now1].x-a[now1].t < b[now2].x-b[now2].t)
{
ansx[a[now1].id] = tx[a[now1].id];
ansy[a[now1].id] = ty[a[now1].id];
now1++;
}
else
{
ansx[b[now2].id] = tx[b[now2].id];
ansy[b[now2].id] = ty[b[now2].id];
now2++;
}
}
while(now1 <= cnt1)
{
ansx[a[now1].id] = tx[a[now1].id];
ansy[a[now1].id] = ty[a[now1].id];
now1++;
}
while(now2 <= cnt2)
{
ansx[b[now2].id] = tx[b[now2].id];
ansy[b[now2].id] = ty[b[now2].id];
now2++;
}
for(int i = ;i <= n;i++) cout << ansx[i] << " " << ansy[i] <<endl;
return ;
}

Codeforces_849的更多相关文章

随机推荐

  1. 【一起学源码-微服务】Ribbon 源码三:Ribbon与Eureka整合原理分析

    前言 前情回顾 上一篇讲了Ribbon的初始化过程,从LoadBalancerAutoConfiguration 到RibbonAutoConfiguration 再到RibbonClientConf ...

  2. yarn详细入门教程(转载)

    简介Yarn 是 Facebook, Google, Exponent 和 Tilde 开发的一款新的 JavaScript 包管理工具.就像我们可以从官方文档了解那样,它的目的是解决这些团队使用 n ...

  3. FastJSON将Java对象转为json,日期显示时间戳未格式化解决办法

    JSON版本:FastJson Java 对象转换为 JSON 格式 定义以下 Person JavaBean: public class Person { @JSONField(name = &qu ...

  4. rest实践1

    REST 即表述性状态传递,是一种针对网络应用的设计和开发,可以降低开发的复杂性.是主流的Web服务实现方案. 表述性状态转移是一组构架约束条件和原则,满足这些约束条件和原则的应用程序和设计就是RES ...

  5. P3369 【模板】普通平衡树 01Trie树

    P3369 [模板]普通平衡树 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入xx数 删除xx数(若有多个相同的数,因只删除一个) 查询xx数的排名(排名 ...

  6. git与github的简单使用教程

    git与github的简单使用教程 一.创建仓库 点击new,进入创建仓库页面 对将要创建的仓库进行一些简单的设置 最后再点击create repository就可以了. 到这我们就创建好了一个仓库. ...

  7. js强制限制输入允许两位小数

    <input type="text" value="@item.CostCash.Value.ToString("#0.00")" c ...

  8. 曹工说Spring Boot源码(11)-- context:component-scan,你真的会用吗(这次来说说它的奇技淫巧)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  9. threding.local

    作用:为每一个线程开辟一个独立的内存空间 示例 from threading import Thread, local import time obj = local() def test(i): o ...

  10. DSSA特定领域软件体系结构

    一.何为DSSA 特定领域软件架构(Domain Specific Software Architecture,DSSA)是一种有效实现特定领域软件重用的手段.简单地说,DSSA就是在一个特定应用领域 ...