HDU 5810 Balls and Boxes

n*(m-1)/(m*m)

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-8;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
    char c = getchar(); while(!isdigit(c)) c = getchar(); int x = 0;
    while(isdigit(c)) { x = x * 10 + c - ‘0‘; c = getchar();  }
    return x;
}

LL n,m;
LL gcd(LL a,LL b){ if(b==0)return a; return gcd(b,a%b); }

int main()
{
    while(~scanf("%lld%lld",&n,&m))
    {
        if(n==0&&m==0) break;
        LL x1=n*(m-1),x2=m*m ;
        LL GCD=gcd(x1,x2);
        if(x1==0) printf("0/1\n");
        else printf("%lld/%lld\n",x1/GCD,x2/GCD);
    }
    return 0;
}
时间: 2024-10-21 20:14:54

HDU 5810 Balls and Boxes的相关文章

HDU 5810 Balls and Boxes(盒子与球)

HDU 5810 Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment

hdu 5810 Balls and Boxes 二项分布

Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 260    Accepted Submission(s): 187 Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experi

hdu-5810 Balls and Boxes(概率期望)

题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he

hdu 4710 Balls Rearrangement (数学思维)

题意:就是  把编号从0-n的小球对应放进i%a编号的盒子里,然后又买了新盒子, 现在总共有b个盒子,Bob想把球装进i%b编号的盒子里.求重置的最小花费. 每次移动的花费为y - x ,即移动前后盒子编号的差值的绝对值. 算法: 题目就是要求                  先判断  n与  lcm(a,b)的大小,每一个周期存在循环,这样把区间缩短避免重复计算. 如果n>lcm(a,b)则   ans = (n/lcm)*solve(lcm)+solve(n%lcm) 否则   ans =

博客园首页新随笔联系管理订阅 随笔- 524 文章- 0 评论- 20 hdu-5810 Balls and Boxes(概率期望)

Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 798    Accepted Submission(s): 527 Problem Description Mr. Chopsticks is interested in random phenomena, and he conducts an experi

【HDU 5810多校】Balls and Boxes(打表/数学)

1.打表找规律,下面是打表程序: #include <iostream> #include <cstdio> #define ll long long #define N 100005 using namespace std; ll n,m,b[N],ans,num; ll sqr(ll x) { return x*x; } void dfs(ll r){ if(r==0){ num++; for(int i=1;i<=m;i++) ans+=sqr(b[i]); retur

HDU 5570 balls 期望 数学

balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5570 Description There are n balls with m colors. The possibility of that the color of the i-th ball is color j is ai,jai,1+ai,2+...+ai,m. If the number of b

hdu 4611 Balls Rearrangement 数学

Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and numbers the boxes from 0 to A-1. To find the balls easily

hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1065    Accepted Submission(s): 536 Problem Description Today, bes