HDOJ 2200

题目大意:

Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目的数量摘录下来,然后从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最小ac数大于第二组中的最大ac数,但是这样的情况会有很多,聪明的你知道这样的情况有多少种吗?

特别说明:为了问题的简化,我们这里假设摘录下的人数为n人,而且每个人ac的数量不会相等,最后结果在64位整数范围内.

哎呀,这题简单,我就不翻译了,直接拷贝过来。。。

题目分析:

明晃晃的找规律。。。但是我找了很久。。。=。=太水了。。。

后来终于想到办法

假设 n =4

如果 2是第一组最小的,那必定2以下的在第二组,2以上的在第一组,并且,可出现,可不出现,所以情况为 第一组*第二组 (2^2)* (2^1-1)  这里减1是因为第二组不能完全为空

所以 如果2是第一组最小的 情况就是 (2^2)* (2^1-1)

同理 如果3是第一组最小的 情况就是 (2^1)* (2^2-1)

同理 如果4是第一组最小的 情况就是 (2^0)* (2^3-1)

看出规律了吧,然后整理,结合等比数列公式,最终公式就是 f(n) = 1+ (n-2)* 2^(n-1)

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int i;
 5     int n;
 6     __int64 sum;   // 64位的整形数
 7     while(scanf("%d",&n) != EOF)
 8     {
 9         sum = 1;
10         sum<<=n-1;//位的左移,相当于乘以2的n-1次方
11         sum =sum * (n-2);
12         sum =sum + 1;
13         printf("%I64d\n",sum);
14     }
15     return 0;
16 }  
时间: 2024-08-28 21:17:56

HDOJ 2200的相关文章

Hdoj 2200 Eddy&#39;s AC难题 【数学】

Eddy's AC难题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4198 Accepted Submission(s): 1967 Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目的数

HDOJ 题目分类

HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:    用STL中的next_permutation()1029:1032:1037:1039:1040:1056:1064:1065:1076:    闰年 1084:1085:1089,1090,1091,1092,1093,1094, 1095, 1096:全是A+B1108:1157:1196:1

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

HDOJ 4901 The Romantic Hero

DP....扫两遍组合起来 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 547    Accepted Submission(s): 217 Problem Description There is an old country and the king fell in love with a

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

关东升终身会员特惠1980,购买即赠价值1599元WOT峰会门票一张+价值2200元Cocos2D-x直播课!

亲爱的学员:        您好!关东升会员限时特惠啦!6月8日前特惠1980元(原价3000元)即可成为终身会员,观看所有付费课程(包括将来要推出的).现在购买还赠送价值2200元Cocos2D-x直播课程!7月18日前购买还赠价值1599元WOT峰会门票一张哟>> 成为关东升会员,您能够获得以下权益:1.亲笔签名iOS高端系列图书一本 : 2.能够学习关老师现有课程和录制的最新课程: 3.提供AppStore开发者账号,帮助学员上线自己开发的App4.享受24小时讲师在线答疑,提供iOS学

【HDOJ】2844 Coins

完全背包. 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[105], c[105]; 5 int n, m; 6 int dp[100005]; 7 8 int mymax(int a, int b) { 9 return a>b ? a:b; 10 } 11 12 void CompletePack(int c) { 13 int i; 14 15 for (i=c; i<=m; ++i) 16 dp[i]