p3412 [POI2005]SKO-Knights
分析
图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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 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 ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- 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][ ...
- POJ 2942 Knights of the Round Table
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 10911 Acce ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
- Knights of the Round Table-POJ2942(双连通分量+交叉染色)
Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...
- poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 9169 Accep ...
随机推荐
- ajaxGet 获取封装
callback 表示下一个功能(回调函数) function ajaxGet(url,callback,data){ 如果路径上有参数 就在url后面拼接参数 否则只请求url ...
- 内置锁(一)synchronized 介绍与用法
一.synchronized 的介绍 synchronized 是 Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码,而这段代码也被称 ...
- Notepad++配置c++编译环境
博主学生狗一只,之前一直进行.net开发,用惯了微软的那一套.C#上手容易,开发起来简单,但是正如前辈们所说的,它隐藏了太多底层的东西,惯坏了我,导致快毕业了有些东西一无所知.同时自己想写点简单的算法 ...
- 1.mybatis实战教程mybatis in action之一开发环境搭建
转自:https://www.cnblogs.com/shanheyongmu/p/5652471.html 什么是mybatis MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框 ...
- 打印机 KX-MB788CN 佳能
打印机 KX-MB788CN http://panasonic.cn/oa/help/download.asp?type=drivers&pid=1066 佳能打印机 腾彩 PIXMA MP2 ...
- Python之filter函数
描述 filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回由符合条件元素组成的新列表. 该接收两个参数,第一个为函数,第二个为序列,序列的每个元素作为参数传递给函数进行判,然后返回 Tru ...
- ios app 生命周期
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/The ...
- ncodeURIComponent() 函数 vue内容
ncodeURIComponent() 函数 编辑 encodeURIComponent() 函数[1] 作用:可把字符串作为URI 组件进行编码.其返回值URIstring 的副本,其中的某些字符 ...
- React Native指南汇集了各类react-native学习资源、开源App和组件
来自:https://github.com/ele828/react-native-guide React Native指南汇集了各类react-native学习资源.开源App和组件 React-N ...
- 提取linux中eth0的IP地址
法1:cut [root@oldboy oldboy]# ifconfig eth0|grep 'inet addr'|cut -d ":" -f2|cut -d " & ...