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\)的最大公共 ...
随机推荐
- js解析json格式
function save(){ var value2 = { "china":[ {"name":"hangzhou", "it ...
- IE(IE6/IE7/IE8)支持HTML5标签--20150216
让IE(ie6/ie7/ie8)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个j ...
- 新建Maven工程,pom.xml报错web.xml is missing and <failOnMissingWebXml> is set to true
错误原因: 项目中没有web.xml 解决办法: 在项目中添加web.xml 在pom.xml中添加下面的插件 <build> <plugins> <plugin> ...
- (14)zabbix Simple checks基本检测
1. 开始 Simple checks通常用来检查远程未安装代理或者客户端的服务 使用simple checks,被监控客户端无需安装zabbix agent客户端,zabbix server直接使用 ...
- usb3.0驱动
usb3.0驱动下载地址 华硕注入usb3.0驱动工具下载地址 https://dlsvr04.asus.com/pub/ASUS/misc/utils/ASUS_EZInstaller_V10306 ...
- Django中重定向页面的时候使用命名空间
urls.py from django.urls import path from . import views app_name='front' urlpatterns = [ path('',vi ...
- python基础——13(系统、时间、序列化模块)
一.时间模块 1.标准库time %y 两位数的年份表示(00-99) %Y 四位数的年份表示(0000-9999) %m 月份(01-12) %d 月中的一天(0-31) %H 24小时制小时数(0 ...
- Mysql 使用命令及 sql 语句示例
Mysql 是数据库开发使用的主要平台之一.sql 的学习掌握与使用是数据库开发的基础,此处展示详细sql 语句的写法,及各种功能下的 sql 语句. 在此处有 sql 语句使用示例:在这里 此处插入 ...
- idea xml 一键生成 javabean
操作步骤 1.复制的xml文件到工程的一个文件下 2.选中文件tools -> XML ACTIONS -> Generate schema from instance Document ...
- Cocoa-Cocoa对象
2.Cocoa对象 2.1 Objective-C是面向对象的语言 Objective-C和Java C++一样,有封装,继承,多态,重用.但是它不像C++那样有重载操作法.模版和多继承,也没有Jav ...