2013年ACM网络赛长春赛区

Cut the Cake

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 294    Accepted Submission(s): 129


Problem Description
MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to decorate the cake (of course they also eat strawberries, not just for decoration). HZ is in charge of the decoration, and he thinks that it's not a big deal that he put the strawberries on the cake randomly one by one. After that, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party will have no cake to eat), and choose one piece first. MMM wants to know the probability that she can get all N strawberries, can you help her? As the cake is so big, all strawberries on it could be treat as points.
 

Input
First line is the integer T, which means there are T cases.
For each case, two integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <= 20, T <= 400)
 

Output
As the probability could be very small, you should output the probability in the form of a fraction in lowest terms. For each case, output the probability in a single line. Please see the sample for more details.
 

Sample Input
   
   
2 3 3 3 4
 

Sample Output
   
   
1/3 4/27
 

Source
 

Recommend
liuyiding


概率问题,题意是说将一个蛋糕切成m块,将n个草莓随机放在蛋糕上,求所有草莓放在同一块蛋糕上的概率。
一开始公式求对了就是n/pow(m,n-1),但是WA了,不解,还也为公式错了。比赛结束之后才知道原来要用大数,瞬间跪了。
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		BigInteger []p=new BigInteger[107];
		int t;
		BigInteger m,gc;
		int n;
		t=cin.nextInt();
		for(int i=1;i<=t;i++){
			m=cin.nextBigInteger();
			n=cin.nextInt();
			m=m.pow(n-1);
			gc=m.gcd(BigInteger.valueOf(n));
			System.out.println(BigInteger.valueOf(n).divide(gc)+"/"+m.divide(gc));
			}
	}

}





Stone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 174    Accepted Submission(s): 132


Problem Description
Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang and Jiang will alternatively write numbers (integers) on a white board. Tang writes first, then Jiang, then again Tang, etc... Moreover, assuming that the number written in the previous round is X, the next person who plays should write a number Y such that 1 <= Y - X <= k. The person who writes a number no smaller than N first will lose the game. Note that in the first round, Tang can write a number only within range [1, k] (both inclusive). You can assume that Tang and Jiang will always be playing optimally, as they are both very smart students.
 

Input
There are multiple test cases. For each test case, there will be one line of input having two integers N (0 < N <= 10^8) and k (0 < k <= 100). Input terminates when both N and k are zero.
 

Output
For each case, print the winner's name in a single line.
 

Sample Input
   
   
1 1 30 3 10 2 0 0
 

Sample Output
   
   
Jiang Tang Jiang
 

Source
 

Recommend
liuyiding

这是这场网络赛最简单的一道题目了,可惜没研究过博弈的只能哭了。
题意是说给你两个数n和k,一个起始数0,两个人开始博弈,俩人轮流往这个起始数上加一个数t(1<=t<=k),当一个人加上一个数大于等于n时,这个人就输了。问谁赢得这场比赛。(k+1)是一个循环,所以当(n-1)%(k+1)==0时就输了,否则赢了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值