传送门

分析

图1

我们假设我们现在有两个向量(2,3)和(4,2),将他们所能到达的点在几何画板上画出来,再将这些点用红线连起来,在将横坐标相同的点用蓝线连起来便能得到图1,就此我们可以发现可以用绿色的两个向量取代之前的两个向量,并且发现有一个向量可以是(0,B)的形式。在发现这个之后我们现在的任务便是求出新向量和原向量的关系了,见下边的推导:

所以我们可以将任何两个向量转变成一个在y轴的向量和一个其它向量。所以我们只需要不断的将向量转变到y轴上使得最终至多一个向量不再y轴上就行了。注意在y轴上的向量我们可以通过取它们的gcd将它们合并成一个向量。详见代码。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int a[],b[];
inline void exgcd(int a,int b,int &x,int &y){
if(b==){
x=;
y=;
return;
}
exgcd(b,a%b,x,y);
int z=x;
x=y;
y=z-(a/b)*y;
return;
}
int main(){
int n,m,i,j,k,x,y;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
}
int a1,b1,a2,b2;
if(!a[]){
a1=a[];
b1=b[];
b2=b[];
}else if(!a[]){
a1=a[];
b1=b[];
b2=b[];
}else {
a1=__gcd(a[],a[]);
exgcd(a[]/a1,a[]/a1,x,y);
b1=b[]*x+b[]*y;
b2=abs(b[]*a[]-b[]*a[])/a1;
}
for(i=;i<=n;i++){
if(!a1){
a1=a[i];
b2=__gcd(b2,b1);
b1=b[i];
}else if(!a[i]){
b2=__gcd(b2,b[i]);
}else {
int be=a1,be2=b1;
a1=__gcd(a1,a[i]);
exgcd(be/a1,a[i]/a1,x,y);
b1=b1*x+b[i]*y;
b2=__gcd(b2,abs(be2*a[i]-b[i]*be)/a1);
}
}
cout<<a1<<' '<<b1<<endl<<<<' '<<b2<<endl;
return ;
}

p3412 [POI2005]SKO-Knights的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. Nike Zoom Winflo 2 Kvinder Sko Når jeg set elementet

    De fleste af os elskede denne Nike Pegasus 34 foruden var ved at blive begejstret for at få dine ben ...

  3. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  4. bzoj 1537: [POI2005]Aut- The Bus 线段树

    bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][ ...

  5. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  6. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  7. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

  8. Knights of the Round Table-POJ2942(双连通分量+交叉染色)

    Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...

  9. poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 9169   Accep ...

随机推荐

  1. 根据inode编号来删除文件或目录

    在Linux系统上,有时候会出现文件名为特殊字符的文件或目录,当我们使用rm来删除这样的文件或目录时,就会出错导致删不掉.但是我们可以依据inode号来删除这样的文件,方法如下: (1)执行ls -i ...

  2. lambda,sorted(),filter(),map(),递归,二分法

    1. lambda 匿名函数 语法: lambda 参数:返回值 不能完成复杂的操作例 # li=['21','asdd','weqeqw','wqf']# # it=iter(li)# # prin ...

  3. 网络基础知识 tcp

    网络基础相关的知识(1)架构a. C / S架构: client客户端和server服务器端 优势: 能充分发挥PC机的性能b. B / S架构: browser浏览器和server服务器 隶属于C ...

  4. java基础:关于java流与文件操作

    1.描述:流是字节数据或字符数据序列.Java采用输入流对象和输出流对象来支持程序对数据的输入和输出.输入流对象提供了数据从源点流向程序的管道,程序可以从输入流对象读取数据:输出流对象提供了数据从程序 ...

  5. tornado-输出,request

    3种输出方法:write render redirectimport tornado.ioloop import tornado.web import tornado.httpserver # 非阻塞 ...

  6. 文件查找find命令

    find命令总结: 常用选项: -name 查找/etc目录下以conf结尾的文件 find /etc -name '*conf' -iname 查找当前目录下文件名为aa的文件,不区分大小写 fin ...

  7. Oracle JOB简例

    JOB declare jobno number; begin dbms_job.submit( jobno, 'insert into tmptable1 values(1,1);', to_dat ...

  8. 怎样在本地windows安装和配置zookeeper

    Zookeeper是什么?有什么用? Zookeeper是一个分布式协调服务. 作用:为用户的分布式应用程序提供协调服务.  zookeeper在底层其实只提供了两个功能: 1.管理(存储,读取)用户 ...

  9. 相对固定位置 relative absolute

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Simple2D-17(音乐播放器)嵌入 ImGui 库

    要把 ImGui 应用到项目中,先拷贝方框中的源文件到项目: 这些文件是 ImGui 的实现源码,可作为第三方库新建一个文件夹进行放置. 接下来是渲染部分的代码,项目可能使用 DirectX 或 Op ...