zoukankan      html  css  js  c++  java
  • hdoj 5194 DZY Loves Balls【规律&&gcd】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5194

    题意:给你n个黑球,m个白球,每次从中随机抽取一个,如果抽到黑球记为1如果抽出来白球记为0,让你输出所有的可能性总数q和将这些组合中01出现的次数q,将q和p以q/p的形式输出最简形式

    竟然就这样过了,只是看到了这个规律试试而已

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define MAX 1010
    using namespace std;
    int gcd(int x,int y)
    {
    	int c;
    	while(y)
    	{
    		c=y;
    		y=x%y;
    		x=c;
    	}
    	return x;
    }
    int main()
    {
    	int n,m;
    	while(scanf("%d%d",&n,&m)!=EOF)
    	{
    		int x=n*m;
    		int y=n+m;
    		int ans=gcd(x,y);
    		printf("%d/%d
    ",x/ans,y/ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    12 go实现几中基本排序算法
    5 控制语句
    9 函数
    4. 常量与运算符
    AI
    AI
    AI
    AI
    ML
    ML
  • 原文地址:https://www.cnblogs.com/tonghao/p/4962358.html
Copyright © 2011-2022 走看看