CodeForces - 261B Maxim and Restaurant】的更多相关文章

B. Maxim and Restaurant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters. Maxim has…
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a3-+ai,问满足Si<=p的i的最大值的期望.(p<=50) (大意来自于http://www.cnblogs.com/liu-runda/p/6253569.html) 我们知道,全排列其实等价于我们一个一个地等概率地向一个序列里面插入数值 所以我们可以这么看这道题: 现在有n个数,有n个盒子…
题意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a3-+ai,问满足Si<=p的i的最大值的期望.(p<=50) 这道题在网上有一些不同的做法,O(n^3)或O(n^4)都可以通过,这里整合一下,标上出处,其实我只写了自己YY的那一种,叫我搬运工 1.期望的线性性,讨论每个数对i的贡献.O(n^4) 自己YY的,不知道以前有没有人也写过这种方法. 如果ai满足Si<=p,那么ai就对答案有1 的贡献,因此我们算出每个数ai满足Si<…
什么什么期望的,不会! (题解http://blog.sina.com.cn/s/blog_140e100580102wj4e.html(看不懂)) #include<bits/stdc++.h> #define LL long long #define LD long double #define N 100005 using namespace std; inline int ra() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch…
题目链接 第一种解法是$O(n^3*p)$的:f[i][j][k]表示前i个人进j个人长度为k有几种方案(排列固定为123..n时).$f[i][j][k]=f[i-1][j][k]+f[i-1][j-1][k-a[i]]$最外层枚举t表示被卡的那个人.i=t时不加上f[i-1][j-1][k-a[i]].$ans={{(\sum f[n][j][k]*j*j!*(n-1-j)!)+(\sum f[n][n][k]*n)}}/(n!)$. 可以看看这篇题解 #include<cstdio> #…
题目链接 想了挺久,枚举每一件物品,当做关键物品,假设再加这一件物品,就>=c了,把剩下的物品背一下包,dp[i][j]表示i个物品可以组成重量j的个数. 这样就可以知道前面放i件,后边肯定放n-i-1件,乱搞搞,算double,边乘边算保证不要越界.最后注意,LL和sum <= c的时候情况. #include <iostream> #include <cstdio> #include <cstring> #include <vector> #…
A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of peopl…
题目链接:http://codeforces.com/contest/854/problem/B 题意: 有n栋房子从1到n排成一排,有k栋房子已经被售出. 现在你要买一栋“好房子”. 一栋房子是“好房子”的要求:(1)没被售出 (2)至少有一栋已售出的房子与他相邻(有邻居) 问你可能的好房子总数量的最小值和最大值. 题解: 贪心. 最小值: 从第1栋房子开始紧挨着往右共k栋全都售出了,好房子只有一栋就是第k栋楼的右边一栋. 特判:k == 0 || n == k:没有好房子,输出0. 最大值:…
题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he…
贪心,优先队列. 先看一下输入的数组乘积是正的还是负的. ①如果是负的,也就是接下来的操作肯定是让正的加大,负的减小.每次寻找一个绝对值最小的数操作就可以了. ②如果是正的,也是考虑绝对值,先操作绝对值最小的那个数,直到那个数字的符号发生变化就停止操作,接下来就是第①步. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #incl…
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须买q[i]个东西,然后他会送你{0,1,2}个物品,但是送的物品必须比你买的最便宜的物品还便宜,问你最少花多少钱,买完m个物品 题解 显然我选择q[i]最小的去买就好了 代码 #include<bits/stdc++.h> using namespace std; const int maxn =…
A. Roma and Lucky Numbers 暴力计算. B. Roma and Changing Signs 每次取最小值改变正负,优先队列维护. C. Maxim and Discounts 贪心,当买的个数等于最小\(q_i\)时,能拿就拿. D. Maxim and Restaurant 枚举最后一个不能上桌的人\(x\),\(f(i,j)\)表示i个人凑成长为\(j\)的方案数,当\(j+a[x] \gt p\)时,前\(i\)个人可以随意排列,而没上桌的人除了\(x\)外也随意…
最近做了好多CF的题的说,很多cf的题都很有启发性觉得很有必要总结一下,再加上上次写题解因为太简单被老师骂了,所以这次决定总结一下,也发表一下停课一星期的感想= = Codeforces 261E Maxim and Calculator 描述:有两个变量a和b,初始值为1和0,每次有两种操作,一个是a=a*b,另一个是b++,求有多少个l<a<r能在p步内达到(p<=100,r<1e9) 首先观察到p最大为100,也就是说最大质因数小于p,打表可得一共大概只有300万个数 考虑d…
A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can…
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/B Description A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order…
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or…
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer…
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最多上一次,所有客人菜单不能相同.给出三种菜的数量,问最多能接收多少客人. 思路: 一人一道 → 一人两道 → 一人三道. #include <bits/stdc++.h> using namespace std; int main() { int t;cin>>t; while(t--…
题目链接:http://codeforces.com/contest/597/problem/B 题目分类:贪心 题目分析:经典的看节目问题(挑战程序设计page 40) 代码: #include<bits/stdc++.h> using namespace std; struct P { int st,en; }order[]; int cmp(P X,P Y) { return X.en<Y.en; } int main() { int n; scanf("%d"…
题目传送门 传送门 题目大意 餐厅有$n$张桌子,第$i$张桌子可以容纳$c_i$个人,有$t$组客人,每组客人的人数等概率是$[1, g]$中的整数. 每来一组人数为$x$客人,餐厅如果能找到最小的$c_j$使得$c_j \geqslant x$,那么就会把这张桌子分配给这些客人,并得到$x$的收益. 问期望的收益. 好像可以枚举每一种人数,然后算一下,但时间复杂度很爆炸. 先添加若干个容量为$\infty$的桌子.这样每组人一定能够分配到一张桌子,只是可能没有收益. 考虑最后答案一定是将桌子…
D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he in…
题目链接 Restaurant 题目意思就是在$n$个区间内选出尽可能多的区间,使得这些区间互不相交. 我们先对这$n$个区间去重. 假如有两个区间$[l1, r1],[l2, r2]$ 若满足$l1 >= l2$且 $r1 <= r2$,那么$[l2, r2]$就是可以被去掉的. 因为这两个区间里我们显然最多只能选择一个. 如果我们在答案里选择了$[l2, r2]$,那么我们如果把$[l2, r2]$换成$[l1, r1]$的话 这个答案肯定还是满足题意的. 甚至可能腾出了可以放下其他区间的…
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个组来餐馆的时候; 按照如下优先顺序安排; ①组内只有一个人的情况 先看有没有空的单人桌,再看有没有空的双人桌,最后看已经有一个人的双人桌 ②组内有两个人的情况 只看双人桌; 如果不能找到符合要求的; 直接拒绝他们的请求; 问:有多少人会被拒绝; [Solution] 注意那里的顺序就好; 另外开一个…
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation…
Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made aa portions of dumplings, bb portions of cranberry juice and cc pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedure o…
传送门 分析:其实没什么好分析的.统计一下负数个数.如果负数个数是偶数的话,就要尽量增加负数或者减少负数.是奇数的话就努力增大每个数的绝对值.用一个优先队列搞一下就行了. 我感觉这道题的细节极为多,非常复杂,其实是自己智障了.. 我看了一下学长菊苣的代码,好精巧...注释部分是他的代码 /*****************************************************/ //#pragma comment(linker, "/STACK:1024000000,10240…
大意: 给定序列, 每次操作选择一个数+x或-x, 最多k次操作, 求操作后所有元素积的最小值 贪心先选出绝对值最小的调整为负数, 再不断选出绝对值最小的增大它的绝对值 #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #inc…
题意:已知一条街上有n幢房子,依次的编号为1~n,其中有k幢已经卖出去了但是不知道是哪k幢.当且仅当一幢房子没有卖出去且其两旁至少有一幢房子卖出去了的时候,认为这幢房子是好的.问这n幢房子中好的房子最多.最少可能有多少. 思路:简单的贪心(但是不小心可能错).首先如果k==n或者k==0,那么显然不可能有任何好的房子.否则,当将所有的卖出去的房子的位置连续地放在街的一端时,好的房子的数量取到最小值1.当n>=k*3时,将n个房子按每三个为一段分开,其中任选k段使中间的那一个房子为卖出去的,那么这…
[链接]h在这里写链接 [题意] 你有n个位置,然后其中有k个地方是已经被人占据了的. 一个"好的位置"的定义是指,这个位置相邻的地方其中至少有一个被人占据了. k个被人占据的位置是不确定的,由你决定. 问你最少的和最多的"好的位置"的个数. [题解] 肯定是010 010 010...这样的安排最优. 也就是3个3个地安排,然后中间放一个被占据的位置. 如果k<=n/3,那么答案就是2*k,因为每个被占据的位置都能产生两个好的位置. 如果k>n/3 如…