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. 并发编程的基石——CAS机制

    本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 Java中提供了很多原子操作类来保证共享变量操作的原子性 ...

  2. DjangoCBV源码分析

    目录 FBV CBV CBV基本写法 CBV源码分析 settings源码分析 FBV FBV是基于函数的视图 CBV CBV是基于类的视图 CBV基本写法 ​ 朝login提交get请求会自动执行M ...

  3. Redis 持久化的两种方案

    reids是一个key-value存储系统,为了保证效率,缓存在内存中,但是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,以保证数据的持久化. 所以:redis是一个支持持 ...

  4. 利用Python进行数据分析学习记录(一)

    1.Python的科学计算邮件列表 pydata:这是一个Google Group邮件列表,其中的问题都是Python数据分析和pandas方面的. pystatsmodels:针对Numpy相关的问 ...

  5. 原生javascript实现仿QQ延时菜单

    一.实现原理 定时器和排他思想 二.代码 <!DOCTYPE html> <html> <head> <title></title> < ...

  6. [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause报错问题的解决

    run SQL: select version(),@@sql_mode;SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','' ...

  7. VS2015发布WEB项目

    第一步:在打开的VS2015中,右击项目,在弹出的对话框中,点击“发布”. 第二步:配置发布的WEB项目. 1.为要发布的项目起个名称,一般和项目名称相同. 2.选择以文件系统发布. 3.设置相关配置 ...

  8. npm 安装出现 run `npm audit fix` to fix them, or `npm audit` for details 解决办法

    1.npm  audit fix 2. npm audit fix --force 3.npm audit 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链 ...

  9. AI漫谈:我们距离实现《庆余年》里的五竹叔机器人还有多远?

    ​(警告: 本文包含少量剧透内容,请酌情阅读)   五竹叔是机器人吗? 看过庆余年的朋友,一定对五竹叔印象深刻,外表英俊潇洒,一袭黑衣加黑布条蒙眼,充满神秘侠客气息.五竹叔不但神秘,而且言行举止常常很 ...

  10. 关于neo4j初入门(3)

    这一章主要是函数的部分 UPPER 它需要一个字符串作为输入并转换为大写字母. UPPER (<input-string>)<input-string>可以是来自Neo4J数据 ...