D. Basketball Team time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GU…
题目链接:点击打开链接 题意: 给定n m h 表示有m个部门,有个人如今在部门h 以下m个数字表示每一个部门的人数.(包含他自己) 在这些人中随机挑选n个人,问挑出的人中存在和这个人同部门的概率是多少. 这个人一定在挑出的n个人中. 反向思考.答案是 1 - 不可能概率 不可能概率 = C(n-1, sum-1-a[h]) / C(n-1, sum-1) 发现2个组合数的分母部分同样,所以仅仅须要把2个组合数的分子部分相除就可以. #include <cstdio> #include <…
简单总结下,留作自己以后拾遗...... 一.find xargs 简单组合 ## mv 小结find ./ -type f -name "*.sh"|xargs mv -t /opt/ find ./ -type f -name "*.sh"|xargs -i mv {} /opt/ find ./ -type f -name "*.sh" -exec mv {} /opt/ \; =====>\转意符号.否则 : 不被shell识别.…
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all members stand in a row , and numbers them 1 \cdots n1⋯n from left to right. The ability of the ii-th person is w_iwi​ , and if there is a guy whose abili…
XKC's basketball team 题意:给定一个序列,从每一个数后面比它大至少 \(m\) 的数中求出与它之间最大的距离.如果没有则为 \(-1\). 题解:从后向前维护一个递增的队列,从后往前遍历,若当前的数大于队尾就进队,否则从该队列中二分找最小的比自己大至少 \(m\) 的数,二者之间的距离即为答案. 若当前数小于队尾,那这个数一定没有队尾的数优,因为它既比队尾的数靠前,又比它小. 时间复杂度 \(O(nlogn)\) . 此题也可以用ST表+二分 等方法写出. 标程(单调队列)…
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all members stand in a row , and numbers them 1 \cdots n1⋯n from left to right. The ability of the ii-th person is w_iwi​ , and if there is a guy whose abili…
C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of…
题意:要求构造一个字符串,要求不能有连续的两个0在一起,也不能有连续的三个1在一起. 分析: 1.假设有4个0,最多能构造的长度为11011011011011,即10个1,因此若m > (n + 1) * 2则肯定不能构造成功. 2.假设有4个0,则至少有3个1,若小于3个,则会有两个连续的0在一起,所以n > m + 1则肯定不能构造成功. 3.当n==m+1时,一定是01串. 4.当m>=n时,应以1为开头构造,根据m和n的个数决定放1个1还是2个连续的1. #include<…
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutput standard output You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The colo…
DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforces.com/problemset/problem/702/A 以为是最长上升子序列(Longest Increasomg Subsequence)的模板题,发现自己不会做 记录一下大概的思路: \(O(n^2)\) 的算法: \(L[i]\) 选择 \(A[i]\) 为结尾的LIS的长度 \(P[i]\)…
题目链接 http://codeforces.com/problemset/problem/735/D 题意:一个人的收入为n他要交的税是n的最大除数,他为了少缴税将n分成k个数n1,n2,n2....nk(k可以为1)所交的税就n1~nk的所有最大约数的和 一道简单的数论题,首先当n为质数是不用分税为1最小,当n为合数是,n为偶数是根据哥德巴赫猜想任意大于2的偶数可以拆成两个质数的和所以最小为 2,n为奇数时由于奇数只能由偶数和奇数组成所以奇数如果拆掉一个2(最小的偶数)剩下的是质数那么n的税…
大家好,欢迎来到codeforces专题. 今天选择的问题是1443场次的D题,这题是全场倒数第三题,截止到现在一共通过了2800余人.这题的思路不算难,但是思考过程非常有趣,这也是这一期选择它的原因. 链接:https://codeforces.com/contest/1443 废话就先说到这里,下面我们就来看题吧. 题意 给定n个整数,对于这n个整数我们可以采取两种操作.第一种操作是在数组左侧选择连续的k个整数减1,第二种操作是选择右侧的连续k个整数减1. 比如假设数组是[3, 2, 2,…
题意: 给你n个数,让你从中选一个子集要求子集中的任何两个数相加都是质数. 思路: 一开始把自己坑了,各种想,后来发现一个简单的性质,那就是两个数相加的必要条件是这两个数之中必定一个奇数一个偶数,(除了含有1 集合以外,1+1等于2也是质数). 考虑两种情况,有1存在和1不存在这两种. 很显然1存在的情况下,所有的1都可以同时在集合中出现,要想集合最大不能加奇数,只能加偶数,那么我们看原始集合中是否有偶数加一是素数. 不考虑1的情况下,这样的子集最大是2,只有存在一个奇数一个偶数相加是质数的情况…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1016G.html 题目传送门 - CF1016G 题意 给定 $n,x,y$ ,以及一个含有 $n$ 个元素的数组 $a$ . 我们称一个数对 $(i,j)$ 是合法的,当且仅当存在一个 $v$ ,使得 $\gcd(a_i,v)=x$ 且 ${\rm lcm} (a_j,v)=y$ . 请你统计有多少合法的 $(i,j)$ 数对. $n\leq 2\times 10^5,1\leq x,y,a_i\le…
题目链接 感觉这题很裸啊,除了看着恶心点也没什么了,怎么过的人那么少.. \(Description\) 给定\(n,r,s\),表示有\(n\)个人,设每个人的得分是非负整数\(a_i\),已知第一个人的得分\(a_1\geq r\),所有人的得分之和\(\sum a_i=s\).得分最高的一个人获胜:若有多个人得分最高,则随机一个人获胜. 求在所有可能情况下,第一个人获胜的概率. \(n\leq100,\ 0\leq r\leq s\leq5000\). \(Solution\) 范围不是很…
http://codeforces.com/contest/932/problem/E 题意:   可以看做 有n种小球,每种小球有无限个,先从中选出x种,再在这x种小球中任选k个小球的方案数 选出的x种不一样,任选k个球的顺序不一样 均视做不同的方案 f[i][j] 表示选了i个小球,来自j种的方案数 那么答案就是 考虑选的第i个球是否是选过的一种, f[i][j]=f[i-1][j]*j+f[i-1][j-1]*(n-(j-1)) #include<cstdio> #include<…
E. Team Work time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people fo…
Android自定义控件有两种,一种是组合.比如一个linearlayout 里面有textview,imageview. 这样的好处是,写一个就可以多处使用. view_image_and_button.xml 你的组合控件的布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res…
Discription It's the turn of the year, so Bash wants to send presents to his friends. There are n cities in the Himalayan region and they are connected by m bidirectional roads. Bash is living in city s. Bash has exactly one friend in each of the oth…
https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1$ 就是左边一个色右边一个色, $m(m-1)$ ,再选转折点有 $i-1$ 种 $C_{i-1}^{1} $( $i$ 个球. $i-1$ 个空挡都可以插). 到 $k=2$ 呢?可以是三种不同颜色,也可以是左右左,也就是 $m(m-1)(m-1)$ ,再选转折点有 $C_{i-1}^{2}$ .…
https://codeforces.com/problemset/problem/1033/C 一开始觉得自己的答案会TLE,但是吸取徐州赛区的经验去莽了一发. 其实因为下面这个公式是 $O(nlogn)$ 的,不是 $O(n²)$ ,所以这样做是可行的.学到了新的知识. $$\sum\limits_{i=1}^{n}\lfloor\frac{n}{i}\rfloor$$ PS:学会LaTeX啦! #include<bits/stdc++.h> using namespace std; #d…
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度为n的合法串是怎么被构造出来的,要么是上一个合法串后面直接连接1,要么是上一个合法串后面连接k个连续的0,那么每个0一一对应于一段连续的0. 所以dp[i]=dp[i-1]+dp[i-k]. 想出来就觉得不难了. #include<bits/stdc++.h> using namespace st…
http://codeforces.com/problemset/problem/909/C 好像以前做过,但是当时没做出来,看了题解也不太懂. 一开始以为只有上面的for有了循环体,这里的statement就可以随便放,但其实并不是这样,statement的位置会取消比它缩进更多或相等的for的可append性.所以设计dp顺序的时候要用dp[i][j]表示第i行剩余可选for循环数量为j的选法数.那么递推公式也不难(才怪),看看代码就好了. 有几个可以优化的,一个是滚动数组,另一个是线性求前…
Description Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and st…
http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html   原 题意:海战棋游戏,长度为n的01串,1代表炸过且没有船的位置,0代表没有炸过的位置.有a个船,长度都是b,求打到一艘船至少还需要多少炸弹,并输出炸的位置. 分析:每连续的b个0就要炸一次,不然不知道有没有是不是刚好一艘船在这b个位置上面.贪心可知炸这b个的最后一个最划算.因为只要炸到一艘即可,所以答案减去a-…
题目链接 题意 : 其实就是要求 分析 : 先暴力将次方通过第二类斯特林数转化成下降幂 ( 套路?) 然后再一步步化简.使得最外层和 N 有关的 ∑ 划掉 这里有个技巧就是 将组合数的表达式放到一边.然后通过组合意义来化简 然后就可以 O( k ^ 2 ) 算出答案了 另外化到后面其实有种产生 这里可以用另外一种方式化简 考虑其组合意义 相当于先从 n 个数中挑出 i 个数.然后再从 i 个数中取 j 个进行排列 其他数可选可不选 具体可以看 Click here #include<bits/s…
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have…
#include <queue> #include <string> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 20000 using namespace std; ][]; int main() { int n; cin>>n; ; j<= && n; ++j){ ;…
I - Parking Lot Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a…
#include <iostream> #include <cstdio> #include<cmath> #include<algorithm> using namespace std; ]; void init_arrary(){ ; i <= ; ++i) { num[i] = num[i - ] + log(i); } } double Cn(int m,int n){ return num[m] - num[n] - num[m-n]; }…