POJ 2657 Comfort
POJ Comfort (扩欧的应用)
题意: n个点顺时针围成一圈(编号1~n),初始时在1点,每次可以顺时针移动k点,n个点中有一些点有障碍物,求最小的k使得在不经过任何一个有障碍物的点就可以到达z点
为了求余方便可以把所有的点-1;
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;int a[1000];
int ex_gcd(int a,int b,int &x,int &y)
{if(b==0){x=1;y=0;return a;}int d=ex_gcd(b,a%b,y,x);y-=x*(a/b);return d;
}
int solve(int a,int b,int c)
{int x, y;int d=ex_gcd(a,b,x,y);if(c%d!=0) return -1;x=x*c/d;int t=b/d;x=(x%t+t)%t;return x;
}
int main()
{int n,z,m,k;while(scanf("%d%d%d",&n,&z,&m)!=EOF){z--;for(int i=0;i<m;i++)scanf("%d",&a[i]),a[i]--;for(k=1;k<=z;k++){int cnt=solve(k,n,z);if(cnt==-1) continue;int flag=1;for(int i=0;i<m;i++){int x=solve(k,n,a[i]);if(x!=-1&&x<cnt) flag=0;}if(flag) break;}printf("%d\n",k);}return 0;
}
一元线性同余式 的计算模板:
int ex_gcd(int a,int b,int &x,int &y)
{if(b==0){x=1;y=0;return a;}int d=ex_gcd(b,a%b,y,x);y-=x*(a/b);return d;
}
int solve(int a,int b,int c)
{int x, y;int d=ex_gcd(a,b,x,y);if(c%d!=0) return -1;x=x*c/d;int t=b/d;x=(x%t+t)%t;return x;
}
POJ 2657 Comfort相关推荐
- POJ 3268 D-Silver Cow Party
http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- poj 2559 Largest Rectangle in a Histogram 栈
// poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...
- POJ 2528 Mayor's posters(线段树)
题目大意 贴海报.每张海报的高度都是一样的,唯独宽度不一样.每张海报只能占用整数倍的单位线段长度,贴了 n(n<=10000) 张海报之后,有几张能够看见(有一个角能看见这张海报也算被看见了)? ...
- POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)
题目链接 题目一看就是最小点覆盖,这道题与POJ - 3041 算是一类题,但是3041算是一道十分裸的,因为删除的是整行或者整列,所以图其实是现成的,但是本题的难点就在如何建图. 思路:首先还是尽量 ...
- poj 2681 字符串
http://poj.org/problem?id=2681 给你任意长度的字符串,找出两串字符中不相同的字符个数(总数) #include<string> #include<cst ...
- (区间dp 或 记忆化搜素 )Brackets -- POJ -- 2955
http://poj.org/problem?id=2955 Description We give the following inductive definition of a "reg ...
- POJ 2586 Y2K Accounting Bug(贪心)
题目连接:http://poj.org/problem?id=2586 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D.公司每五个月进行一次统计,全年共统计8次( ...
- poj 2362 Square
#include <iostream> //参照poj 1011 sticks#include <algorithm>using namespace std;int stick ...
- 图论之拓扑排序 poj 2367 Genealogical tree
题目链接 http://poj.org/problem?id=2367 题意就是给定一系列关系,按这些关系拓扑排序. #include<cstdio> #include<cstrin ...
最新文章
- IP地址审计在事件追溯中的应用
- python手机版idle-Python IDLE下载
- 粒子群优化算法_每日论文19:粒子群优化算法综述
- 【体验】感谢热心网友送的3D打印结构外壳,nodemcu外壳,3D打印wifi外壳
- jbpm4.4+ssh配置
- 干货|一文读懂阿里云数据库Autoscaling是如何工作的
- Oracle 以某字段分组,以某字段排序,取前几条
- RuntimeError: expected backend CUDA and dtype Float but got backend CUDA and dtype Long
- 【论文】PathQG: 基于事实的神经问题生成
- paip.提高稳定性---自动检测sleep mysql数据库死连接以及kill
- 【Python】python帮助文档
- ubuntu wine protel 99se安装
- js和jsp的区别和联系
- wstmall wstmart wstshop区别
- 用JS写一个《俄罗斯方块》小游戏
- 【离散数学】点割集(割点集)与边割集详解
- [转] mybatis调用存储过程(jeeplus)
- Linux驱动emmc的8bits/4bits/1bits模式自动匹配优化
- Android连上USb不充电,为什么手机usb连不上电脑只显示充电 安卓手机解决方法
- 【图和树基础】完全图判定