Cards
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/K

Description

You have N cards with different numbers on them. Your goal is to find a card with a maximal number. At the beginning all cards are put into the hat. You start getting them one by one and look at the numbers on them. After each card you can select it and stop the process. If it is really the card with the maximal number you win otherwise you lose. Also you can skip the current card and continue process. Fortunately you have a friend who helps with a good strategy: you pull X cards and memorize their values. Then you continue the process and select as answer the first card with value greater than the maximal value you memorized. Unfortunately you don't know the value of Xthat maximizes you chances of winning. Your task is to find X.

Input

Single line containing one number: N (5 ≤ N ≤ 100).

Output

Single line containing one number: value of X that maximizes you chances of winning.

Sample Input

5

Sample Output

2

题解

这道题可以暴力打表,而且貌似效果比较好。。我的做法是枚举X,再枚举X中最大的数a,那么X对应的概率应当是sum(C(a-1,x-1)/(C(n,x)*(n-a), x<=a&&a<n),这样统计好后,取最大的X即可,详见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 1000000005
#define eps 1e-10
#define PI acos(-1.0)
#define K (0.017453292519943295769236907684886l)
#define LL long long
#define ULL unsigned long long using namespace std; const int maxn = 100005; int a[maxn], n, m; struct Node
{
int val, pos;
}B[maxn]; bool cmp(const Node &x, const Node &y)
{
return x.val < y.val;
} LL Bel[maxn], Num[maxn], Prod[maxn]; int Get(int x)
{
if (x > B[m].val) return m;
int l = 1, r = m, pos = 0;
while(l <= r)
{
int mid = (l + r) / 2;
if (x >= B[mid].val)
{
pos = mid; l = mid + 1;
}
else r = mid - 1;
}
return pos;
} int main()
{
LL ans = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
{
scanf("%d", &B[i].val);
B[i].pos = i;
}
sort(B + 1, B + 1 + m, cmp);
for (int i = 1; i <= m; i++)
{
Bel[i] = Bel[i - 1] + B[i].pos;
Num[i] = Num[i - 1] + B[i].val;
Prod[i] = Prod[i - 1] + 1LL * B[i].pos * B[i].val;
// printf("%I64d %I64d %I64d\n", Bel[i], Num[i], Prod[i]);
}
for (int i = 1; i <= n; i++)
{
int pos = Get(a[i]);
// printf("%d\n", pos);
ans = ans + 1LL * pos * i * a[i] + Prod[pos];
ans = ans - 1LL * a[i] * Bel[pos] - 1LL * i * Num[pos];
//
// if (i == 1) printf("%I64d\n", ans);
LL temp = 1LL * (m - pos) * i * a[i] + Prod[m] - Prod[pos];
temp = temp - 1LL * a[i] * (Bel[m] - Bel[pos]) - 1LL * i * (Num[m] - Num[pos]);
ans -= temp;
// if (i == 1) printf("%I64d\n", ans);
}
printf("%I64d\n", ans);
return 0;
}

最新文章

  1. 2015年12月10日 spring初级知识讲解(三)Spring消息之activeMQ消息队列
  2. flexigrid随手记
  3. 十年学会编程 著者: Peter Norvig 翻译: Dai Yuwen
  4. iOS app性能优化的那些事
  5. 【USACO】
  6. log4j自动生成日志文件配置
  7. ruby sass Encoding::CompatibilityError for changes
  8. mysql的架构
  9. jquery学习笔记3 jq遍历
  10. PostgreSQL相关整理
  11. P1119 灾后重建 floyd
  12. 关于在UNIcode环境下得TCHAR转string类型以及string转TCHAR
  13. 图解HTTP第四章
  14. Javascript鼠标键盘事件
  15. Confluence 6 通过 SSL 或 HTTPS 运行 - 备注和问题解决
  16. 理解面向过程(OPP)、面向对象(OOP)、面向切面(AOP)
  17. (原)MobileNetV1
  18. 子数组最小值的总和 Sum of Subarray Minimums
  19. 代码UITableView点击cell跳转
  20. Beans Game(博弈 | | DP)zoj 3057

热门文章

  1. Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载
  2. 【NOIP2017提高A组冲刺11.6】拆网线
  3. [JOY]1143 飘飘乎居士的约会
  4. 【Java_基础】java类加载过程与双亲委派机制
  5. 使Linux支持exFAT和NTFS格式的磁盘
  6. 微信小程序 wx.request POST请求------中文乱码问题
  7. GIMP素描效果
  8. Python中变量的命名与使用(个人总结)
  9. python 列表(增删改查)
  10. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph