UVA 10277 Boastin' Red Socks
#include <iostream>
#include<cstdio>
#include<cstring> using namespace std; unsigned int r,sum,p,q;
unsigned int st[][]; unsigned gcd(unsigned a,unsigned b)
{
return b?gcd(b,a%b):a;
}
/*哈希链表*/
const int HASH=;
int head[HASH],next1[HASH];
int hash1(unsigned int &s)
{
return s%HASH;
}
int insert(int s)
{
int h=hash1(st[s][]);
int u=head[h];
while(u)//链表尾一直是0,所以s不能为0
u=next1[u];
next1[s]=head[h];//原来的链表头成为s的next
head[h]=s;//s成为head[h]的链表头
return ;
}
int find(unsigned int s)
{
int h=hash1(s);
int u=head[h];
while(u)
{
if(st[u][]==s) return u;
u=next1[u];
}
return ;
}
int main()
{
//freopen("/home/user/桌面/in","r",stdin);
while(scanf("%u%u",&p,&q)==&&(p||q))
{
memset(head,,sizeof(head));
unsigned int i=,x,j=;
if(p==)
{
printf("%d %d\n",,);
continue;
}
x=gcd(p,q);
p/=x;q/=x;
for(;i<=;i++)
{
unsigned int t=i*i-i;
if(t%p==)
{
st[j][]=t/p;
st[j][]=i;
insert(j);
j++;
}
if(t%q==&&(x=find(t/q)))
{
printf("%u %u\n",st[x][],i-st[x][]);
break;
}
}
if(i>) puts("impossible");
}
return ;
}
UVA 10277 Boastin' Red Socks的更多相关文章
- 10277 - Boastin' Red Socks
描述:红黑袜子,给出的是红袜子被选到的概率,即为p/q,要计算的是在挑选出一对红袜子之前的红袜子和黑袜子的数目,假设红袜子数为n,黑袜子数为m,那么n(n-1)/(m(m-1))=p/q,求出红袜子数 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- cf581A Vasya the Hipster
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red so ...
- Vasya the Hipster
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red so ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA 253 Cube painting(暴力打表)
Cube painting Problem Description: We have a machine for painting cubes. It is supplied with three d ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
随机推荐
- Xcode-App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
在xcode中上报数据时候,logserver一直没有数据,后来发现控制台有一个提示: 找了半天是因为Xcode7禁止明码的HTTP请求,而自己使用的是Xcode7.2.1 解决办法:修改info.p ...
- windows下9款一键快速搭建PHP本地运行环境的好工具(含php7.0环境)
推荐几款一键快速搭建PHP本地运行环境的好工具(含php7.0及apache,nigix,mysql) 首推phpstudy2016和wampServer3.0.6 理由支持php7.0 目前 ...
- POJ 3259 Wormholes(SPFA+邻接表)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<queue> #include<vector ...
- 三、ASP.NET MVC Controller 控制器(二:IController控制器的创建过程)
阅读目录: 1.开篇介绍 2.ASP.NETMVC IControllerFactory 控制器工厂接口 3.ASP.NETMVC DefaultControllerFactory 默认控制器工厂 4 ...
- OpenCV2.x自学笔记——最大类间方差法OTSU
推荐用法:(参数勿动) threshold(gray,binary,0,255,CV_THRESH_OTSU+CV_THRESH_BINARY);
- TypeError: document.getELementById is not a function
这个错误困扰了我好几个小时,在网上也百度了好久类似的问题但都没有结果,反反复复看了好多遍,才发现,原来是document.getELementById 里面的Element的字母 l 我写成了大写的L ...
- 关于springboot启动时候报错:springboot Failed to parse configuration class [Application]
把运行的java类放在一个package下后就不再提示这个错误. 使用的ide是intellij,之前也有因为没有创建package报错的经历,可能这是intellij必须的
- 全排列dfs算法
如下 #include <iostream> using namespace std; #define MAX 10 #define _CRT_SECURE_NO_WARNINGS int ...
- MYSQL:SQL中Group By的使用
SQL中Group By的使用 1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By ...
- MySQL5.7以上开启binlog
在my.cnf的mysqld下加入: server_id = 0 log_bin=/harddisk/mysql_data/mysql_binlog/mysql-bin binlog_format ...