Codeforces Gym 100418K Cards 组合数学
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;
}
Codeforces Gym 100418K Cards 组合数学的更多相关文章
- Codeforces Gym 100418K Cards 暴力打表
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- codeforce Gym 100418K Cards (概率,数学)
题意:麦田的故事,n张牌,取x张牌,记住前x张牌最大的值m,继续往后取,遇到第一张比m大的牌就停下来.求一个x使得最后的牌在整副牌里是最大的期望最大. 假设最大的牌是A,A在各种位置出现的概率就是相等 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- ssh 免密码登录 与 密钥公钥原理讲解
前言 由于最近频繁需要登录几个服务器,每次登录都需要输入密码,故相对麻烦. 由于个人服务器用于实验,故对安全性要求不是很高,故想实现ssh免密登录. 通过阅读ssh 公钥私钥认证操作及原理以及ssh公 ...
- Spark 2.0.0 SPARK-SQL returns NPE Error
com.esotericsoftware.kryo.KryoException: java.lang.NullPointerExceptionSerialization trace:underlyin ...
- WordPress的编译器功能扩展
//php代码如下://向文章编辑器的Visual区添加自定义按钮,js文件存放在wp-content/plugins/文件夹下 add_action('admin_head', 'my_custom ...
- 【编程工具】Sublime Text3 之 Emmet 插件的详细使用的方法
这篇关于 Emmet 插件使用的博文之前就想写了,今天刚好闲暇时间,就花了一些时间进行了总结. 我们都这道 Emmet 这款插件在前端设计里被称为神器,确实,神器称号名不虚传.因为这款插件可以帮助我们 ...
- sql语句中的join连接(左连接、右连接、全连接、内连接)
内部连接(inner join): select * from d_user a inner join D_ORGANIZATION b on a.COMPANY_XID=b.ID 内部链接也是排他 ...
- 九度oj 题目1028:继续畅通工程
题目描述: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用 ...
- JAVA如何解压缩ZIP文档
代码片段: package org.yu.units; import java.io.Closeable; import java.io.File; import java.io.FileInputS ...
- 08-为数组和arguments
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Android隐藏软键盘收回软键盘
代码改变世界 Android隐藏软键盘收回软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPU ...
- JSF框架整理
JSP体系结构: JSF主要优势之一就是它既是Java web 应用程序的用户界面标准又是严格遵循 模型-视图-控制器(MVC)设计模式的框架. 用户界面代码(视图)和应用程序数据和逻辑(模型)的清晰 ...