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 ...
随机推荐
- c# delegate的invoke和bejinInvoke的区别
先看下面实实例代码 private delegate void testdg(); private void button1_Click(object sender, EventArgs e) ...
- js禁止浏览器后退,防止重复支付
<script language="JavaScript"> javascript:window.history.forward(1);</script>
- linux 查看日志
第一步 :提交自己目录文件(先到自己目录下载最新文件-->合并-->提交到临时目录temp-->在提交到master总目录-->其他关联master远 程分支的目录.就可以pu ...
- 对Big O的新的认识
对Big O的新的认识 一个问题,它有很多种算法都能实现.每种算法它的时间.空间复杂度不一样.比如: 问题1: 求最大连续子序列和的问题,可以有O(n3).O(n2).O(nlogn)和O(n)四种时 ...
- OMCS开发手册(03) -- 多媒体服务器
前面我们已经详细介绍了基于OMCS开发网络多媒体应用的客户端程序所必需掌握的内容,现在我们来看一下OMCS服务端的开发.对于使用者而言,OMCS的服务端就非常简单了,只要实现一个用户验证的接口,挂接到 ...
- 将数据库的数据导入solr索引库中
在solr与tomcat整合文章中,我用的索引库是mycore,现在就以这个为例. 首先要准备jar包:solr-dataimporthandler-4.8.1.jar.solr-dataimport ...
- erlang套接字
Erlang的套接字可以有三种打开模式:主动(active).单次主动(active once)或被动(passive).这是通过在gen_tcp:connect(Address, Port, Opt ...
- javascript动画效果之匀速运动
html和css写在一起方便看,div通过定位设置为-200隐藏,span也是通过定位定在div靠左的中间 <!DOCTYPE html> <html> <head> ...
- 数据库 mysql 语句
LAMP: Linux系统 A阿帕奇服务器 Mysql数据库 Php语言 mysql:常用代码 create table CeShi1( Uid varchar(50) primary key, Pw ...
- Pots(BFS)
Pots Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submiss ...