[Zhengqing] [1760] Interesting game

Problem Description

Loading...

Problem Analysis

Yet another piece of code that once got WA:
Rewritten now…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
int main() {
	int i,m,n,a,b;
	while(scanf("%d %d",&n,&m)!=EOF) {
		if(n==0||m==0)
			printf("0\n");
		else {
			for(i=1,a=n; i<m; i++) {
				a=n*(n-1);
				n--;
			}
			for(i=1,b=m; i<m; i++) {
				b=m*(m-1);
				m--;
			}
			printf("%d\n",a/b);
		}
	}
	return 0;
}

Lights out…
Turn on mobile data and have some fun~

Well… failure
Let’s save it for now…
Look at it later

======20160213==writing the following======
Third time looking at this problem…
Finally solved it
Found the tricky part of the data in this problem

It was supposed to be a simple permutations and combinations problem
But it came with some inhuman input/output

The trickiest part is probably
when m==0 it actually asks you to output 1
Choosing 0 items still counts as 1 way—I’m speechless -.-

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF) {
		if(m==n||m==0)
			printf("1\n");
		else if(m>n||m<0||n<=0)
			printf("0\n");
		else {
			if(m>n/2)
				m=n-m;
			int sum=n;
			for(int i=1; i<m; i++) {
				sum*=--n;
			}
			int summ=m;
			while(m>1)
				summ*=--m;
			printf("%d\n",sum/summ);
		}
	}
	return 0;
}

Problem link: ZZULI 1760 Interesting game

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...