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. Django之models字段属性

    目录 常用字段 AutoField IntegerField CharField 自定义及使用char DateField DateTimeField 字段合集 字段参数 null unique db ...

  2. 2020 年 Java 程序员应该学习什么?

    大家好,我相信大家在新的一年都有一个良好的开端,并准备好制定一个提升自我技术的目标.作为 Java 开发人员,我还制定了一些目标,希望在今年成为一名更好的 Java 开发人员. 如果你尚未制定目标,这 ...

  3. CF749D Leaving Auction set排序查找

    CodeForces 749D. Leaving Auction 传送门 There are n people taking part in auction today. The rules of a ...

  4. 基于Netty和SpringBoot实现一个轻量级RPC框架-Client篇

    前提 前置文章: <基于Netty和SpringBoot实现一个轻量级RPC框架-协议篇> <基于Netty和SpringBoot实现一个轻量级RPC框架-Server篇> 前 ...

  5. Spring Boot2 系列教程(一) | 如何使用 IDEA 构建 Spring Boot 工程

    微信公众号:一个优秀的废人 如有问题或建议,请后台留言,我会尽力解决你的问题. Search 前言 新年立了个 flag,好好运营这个公众号.具体来说,就是每周要写两篇文章在这个号发表.刚立的 fla ...

  6. 区间dp - 括号匹配并输出方案

    Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular seque ...

  7. SpringCloud组件和概念介绍(一)

    一:什么是微服务(Microservice) 微服务英文名称Microservice,Microservice架构模式就是将整个Web应用组织为一系列小的Web服务.这些小的Web服务可以独立地编译及 ...

  8. eclipse开发工具内打开某js文件总是用记事本方式打开的问题

    问题现象: 开发时不知道按到了什么快捷键,导致在某js文件内点击某调用方法时莫名其妙的用记事本方式打开了该js文件,试了几次都是这样.索性将该js文件关掉重新打开,结果双击该文件还是弹出了一个记事本, ...

  9. 20191014Java课堂记录

    1. Java字段初始化的规律 首先执行类成员定义时指定的默认值或类的初始化块,到底执行哪一个要看哪一个“排在前面”. 其次执行类的构造函数. 类的初始化块不接收任何的参数,而且只要一创建类的对象,它 ...

  10. Mysql.linux登录数据库

    //mysql -hlocalhost -uroot -p //-h数据库地址 -u用户名 -p密码 -P端口号(P大写)//-p可省略,会提示输入密码. mysql -h127. -uroot -p ...