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. DNS服务器红帽5.4搭建图文教程!!!

    DNS服务器 挂载光盘 mount 查看光盘所在位置 mount -t iso9660 设备目录 /mnt 表示挂载 软件包安装 所有软件包都在Server目录下 rpm -ivh /mnt/Serv ...

  2. 6.7 Mapreduce作业流JobControl和Oozie

    1.1  Mapreduce作业流JobControl和Oozie 更复杂的任务,需要多个mapreduce作业,形成作业流,而不是增加map和reduce的复杂度.复杂问题,可以用高级语言pig.h ...

  3. (1)解锁 MongoDB replica set核心姿势

    副本集Replica Set是一个术语,定义具有多节点的数据库集群,这些节点具有主从复制(master-slave replication) 且节点之间实现了自动故障转移. 这样的结构通常需要具有奇数 ...

  4. 区间dp - 送外卖

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...

  5. 【python系统学习05】input函数——实现人机交互

    input函数 目录 input用途 语法 示例 参数 返回值 返回值数据类型转换 容错处理 动手吧 input用途 实现人机交互: 1.你提出问题打印在屏幕上, 2.运行程序的人再输入回答. 3.按 ...

  6. 3.JavaSE之注释

  7. 高通量计算框架HTCondor(四)——案例准备

    目录 1. 正文 1.1. 任务划分 1.2. 任务程序 2. 相关 1. 正文 1.1. 任务划分 使用高通量计算第一步就是要针对密集运算任务做任务划分.将一个海量的.耗时的.耗资源的任务划分成合适 ...

  8. prometheus和zabbix的对比

    前言: 新公司要上监控,面试提到了Prometheus 是公司需要的监控解决方案,作为喜新厌旧的程序员,我当然是选择跟风了,之前主要做的是zabbix,既然公司需要prometheus,那没办法,只能 ...

  9. JUC中的原子操作类及其原理

    昨天简单的看了看Unsafe的使用,今天我们看看JUC中的原子类是怎么使用Unsafe的,以及分析一下其中的原理! 一.简单使用AtomicLong 还记的上一篇博客中我们使用了volatile关键字 ...

  10. MEF sample

    博客里介绍ntier 基于这个框架有一个叫WAF的示例项目. 看 waf(WPF Application Framework)里面这样有句 不是很懂, This page might help you ...