码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1599: [Usaco2008 Oct]笨重的石子( 枚举 )

时间:2015-06-06 14:53:57      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

直接枚举 

-------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ;  i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
#define Rep( i , n ) for( int i = 1 ; i<= n ; ++i ) 
 
using namespace std;
 
const int maxn = 80 + 5;
  

int cnt[ maxn ];

 
int main() {
clr( cnt , 0 );
int x[ 3 ];
rep( i , 3 )
   scanf( "%d" , x + i );
   
Rep( i , x[ 0 ] )
   Rep( j , x[ 1 ] )
       Rep( k , x[ 2 ] )
           cnt[ i + j + k ]++;
       
int Max = 0 , ans;
rep( i , maxn )
   if( cnt[ i ] > Max )
       Max = cnt[ ans = i ];
cout << ans << "\n";
return 0;
}

  

-------------------------------------------------------------------------------

1599: [Usaco2008 Oct]笨重的石子

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 820  Solved: 561
[Submit][Status][Discuss]

Description

贝西喜欢棋盘游戏和角色扮演类游戏所以她说服Farmer John把她带到玩具店,在那里,她购买了三个不同的骰子,这三个质量均匀的骰子,分别有S1,S2,S3个面。(2 <= S1 <= 20; 2 <= S2 <= 20; 2 <= S3 <= 40). 贝西掷啊掷啊掷啊,想要知道出现几率最大的和是多少。 问题给出三个骰子的面数,让你求出出现几率最大的和是多少。如果有很多种和出现的几率相同,那么就输出小的那一个。

Input

*第一行:三个由空格隔开的整数:s1,s2,s3

Output

*第一行:所要求的解

Sample Input

3 2 3

Sample Output

5


输出详解:


这里是所有可能的情况.

1 1 1 -> 3 1 2 1 -> 4 2 1 1 -> 4 2 2 1 -> 5 3 1 1 -> 5 3 2 1 -> 6

1 1 2 -> 4 1 2 2 -> 5 2 1 2 -> 5 2 2 2 -> 6 3 1 2 -> 6 3 2 2 -> 7

1 1 3 -> 5 1 2 3 -> 6 2 1 3 -> 6 2 2 3 -> 7 3 1 3 -> 7 3 2 3 -> 8

5和6出现的几率都是最大的,所以输出5.

HINT

Source

 

BZOJ 1599: [Usaco2008 Oct]笨重的石子( 枚举 )

标签:

原文地址:http://www.cnblogs.com/JSZX11556/p/4556581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!