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 ...
随机推荐
- dplyr 数据操作 数据过滤 (filter)
在R的使用过程中我们几乎都绕不开Hadley Wickham 开发的几个包,前面说过的ggplot2.reshape2以及即将要讲的dplyr 因为这几个包可以非常轻易的使我们从复杂的数据操作中逃离, ...
- html中的js监听付款按钮--触发ajax调用php后台--得到的json数据---交给安卓原生处理
//01 var pay_status = new Object();$(".sure_pay").on("touchstart",function(){ va ...
- 14.hibernate的反向生成实现全套增删改查
图片顺序就是步骤顺序 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.
- 利用PYTHON设计计算器功能
通过利用PYTHON 设计处理计算器的功能如: 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 ))- (-4*3 ...
- 【入门一】一些简单的C程序及VS的安装
实例1 用 printf 函数打印字符串 # include <stdio.h> // 预处理指令,结尾不加 ';' int main(void) // int表示该函数将返回一个整数值, ...
- 正则表达式 Pattern & Matcher
1 compile and pattern Pattern类用于创建一个正则表达式,也可以说创建一个匹配模式,它的构造方法是私有的,不可以直接创建,但可以通过Pattern.complie(Strin ...
- 快速破解ps方法
1.首先现在ps安装包和破解包. 2.运行Block Adobe Activation,防止ADOBE激活程序启动,按操作提示即可. 3.运行Adobe CS6安装程序. 4.选择“试用”. 5.输入 ...
- javaweb学习总结——Filter高级开发
在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...
- Android底部导航栏创建——ViewPager + RadioGroup
原创文章,引用请注明出处:http://www.cnblogs.com/baipengzhan/p/6270201.html Android底部导航栏有多种实现方式,本文详解其中的ViewPager ...
- CentOS挂载硬盘
1.查看当前硬盘使用状况: [root@gluster_node1 ~]# df -h 文件系统 容量 已用 可用 已用%% 挂载点 /dev/sda3 14G 2.4G 11G 19% / ...