题解:P10852 【MX-X2-T1】「Cfz Round 4」Awaken
upd:修正了读取两个
题目大意
给定一个长度为
对于所有满足
思路
实际上要求序列是一个等差数列
考虑特殊情况:
取
对于等差数列
两者相等,满足条件。
实现
比较简单,需要注意一下特殊情况。
如果 Yes。
如果 Yes。
如果
先将已知点按位置排序,再计算相邻点的位置差和值差,确定公差
如果所有点都满足且公差为整数,输出 Yes,否则输出 No。
代码
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ull unsigned long long
#define int long long
using namespace std;
using ll=long long;
inline void read(int& a) {
int w=1;char c;a=0;
while((c=getchar())<'0'||c>'9')if(c=='-')w=-1;
do a=a*10+(c^48); while((c=getchar())>='0'&&c<='9');
a*=w;
}
void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
return ;
}
const int N=1e9;
void solve(){
int n,m;
read(n),read(m);
vector<pair<int,int>>a(m);
for(int i=0;i<m;i++)read(a[i].first),read(a[i].second);
if(m<=1){
puts("Yes");
return;
}
sort(a.begin(),a.end());
bool is=1;
int num=a[1].second-a[0].second;
int numm=a[1].first-a[0].first;
if(num%numm!=0)is=0;
else {
int d=num/numm;
int pos=a[0].second-(a[0].first-1)*d;
for(auto [x,y]:a){
if(pos+(x-1)*d!=y){
is=0;break;
}
}
}
if(is)puts("Yes");
else puts("No");
}
signed main() {
int T;
read(T);
while(T--)solve();
return 0;
}
//
// ⠀⢸⣿⣿⣿⠀⣼⣿⣿⣦⡀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀ ⠀⢸⣿⣿⡟⢰⣿⣿⣿⠟⠁
// ⠀⠀⠀⠀⠀⠀⠀⢰⣿⠿⢿⣦⣀⠀⠘⠛⠛⠃⠸⠿⠟⣫⣴⣶⣾⡆
// ⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠉⢿⣦⡀⠀⠀⠀⠀⠀⠀ ⠛⠿⠿⣿⠃
// ⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣦⠀⠀⠹⣿⣶⡾⠛⠛⢷⣦⣄⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠈⠉⣀⡀⠀ ⠀⠙⢿⡇
// ⠀⠀⠀⠀⠀⠀⢀⣠⣴⡿⠟⠋⠀⠀⢠⣾⠟⠃⠀⠀⠀⢸⣿⡆
// ⠀⠀⠀⢀⣠⣶⡿⠛⠉⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⢸⣿⠇
// ⢀⣠⣾⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⢀⣼⣧⣀⠀⠀⠀⢀⣼⠇
// ⠈⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠋⠙⠛⠛⠛⠛⠛⠁
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⡿⠋⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⢾⠿⠋⠀