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 ...
随机推荐
- SyntaxError: Non-ASCII character ‘\xe5′ in file
在写一个抓取网页的小脚本,运行起来总是出现这个错误 查了下Python的默认编码文件是用的ASCII码,你将文件存成了UTF-8也没用,解决办法很简单 只要在文件开头加入 # -*- coding: ...
- servlet里的过滤器filter
过滤器的主要作用 1,任何系统或网站都要判断用户是否登录. 2,网络聊天系统或论坛,功能是过滤非法文字. 3,统一解决编码 怎么创建一个过滤器: 1,生成一个普通的class类,实现Filter接口( ...
- leetcode965
public class Solution { List<int> list = new List<int>(); private void postTree(TreeNode ...
- EventUtil——跨浏览器的事件对象
. 首页 博客园 联系我 前言:什么是EventUtil?. EventUtil对象全见. addHandler方法. removeHandler方法. event对象与getEvent方法. tar ...
- delphi XE7 判断手机返回键
Using the Android Device's Back Button To make your application handle when users press the Back but ...
- 可视化库-seaborn-回归分析绘图(第五天)
1. sns.regplot() 和 sns.lmplot() 绘制回归曲线 import numpy as np import pandas as pd from scipy import stat ...
- mongodb基础学习1-基本说明及安装
以前看过一些mongodb的视频,但只看到一半没有看完,也没有同步安装软件动手操作,正好最近没事,打算花点时间从头学习一遍,边学习边动手操作,学习的过程在此进行记录. 好了,下面说一下今天的学习内容. ...
- PPT地图 - 动态显示省份扩散效果
找一张中国地图矢量图,这个要找半天,自己画难度有点大.图中每个省份都是单独一张图.从我的百度云盘下载 提取码: 61ha 选中一个省份图块并复制,填充复制图块的颜色,拖拽该图块覆盖住该省份原来位置. ...
- 吴裕雄 实战PYTHON编程(5)
text = '中华'print(type(text))#<class 'str'>text1 = text.encode('gbk')print(type(text1))#<cla ...
- stl-stack+括号配对问题
栈:stl的一种容器,遵循先进后出原则,,只能在栈的顶部操作,就像放盘子一样,洗好的盘子叠在上面,需要用时也是先从顶部拿.不允许被遍历,没有迭代器 基本操作: 1.头文件#include<sta ...