CodeForces 337A Puzzles】的更多相关文章

Puzzles Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 337A64-bit integer IO format: %I64d      Java class name: (Any) The end of the school year is near and Ms. Manana, the teacher, will soon have t…
题目链接:http://codeforces.com/problemset/problem/337/A 题意:有n个学生,m块puzzles,选出n块puzzles,但是需要满足这n块puzzles里的最大pieces(A)和最小pieces(B)之差最少,即the least possible difference. 这是一道贪心兼排序的题目,解决方法不难.首先对m块puzzles以非递减的顺序排序(可以保证每个n长度的区间difference最小),接着求出所有长度为n的区间中最大和最小的值…
A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/337/A Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to p…
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不同的点的数量+1) 每一次只有当子树中所有的点都已经游走过了再会向父亲走,走到每个儿子上的概率是相同的 对于每个点,求他的权的期望 (1 ≤ n ≤ 10^5) 题解: 首先我们发现,所有子树中所有的点的编号都一定比父亲要大 而且子树中的大小关系和我们访问它的顺序有关 如果对于一个节点u它的儿子为v…
题目链接: http://codeforces.com/problemset/problem/696/B 题目大意: 给一棵树,从根节点开始递归,time=1,每次递归等概率随机访问这个节点的子节点,走过不会再走,每访问到一个新节点time+1,求访问每个节点的时间的期望. 题目思路: [数学规律] 这题其实是一道概率DP的题目,但是找规律后发现答案和当前结点的子树大小有关. ans[v]=ans[u]+1+0.5*(child[u]-child[v]-1),child为当前节点的子树大小. /…
传送门:D - Puzzles 题意:在一个图中,从1开始dfs,求每一个点到达的期望: 思路:(下面是队长写的) 首先求的是到每一个点的步数的期望. 记fa( u ) = v, son( v )表示v的儿子的集合, z是son(v)中的点,其中 z != u ,  sum[z] 为 z 的子树的大小, p( z )表示z比u先访问到的概率; 那么可以发现对于u来说 ans[u] = ans[v] + 1 + x; 现在我要来算这个x, 如果 son(v).size == 1, 那么x为0; 否…
题意:给一棵有根树,从根节点深搜,每次随机走,问每个点的dfs序的期望是多少 分析:对于每一个点,它的所有祖先节点dfs序肯定在它之前,它所在的子树的节点一定在它后面, 剩下的是既不是子树又不是祖先的节点,可能在它之前,也可能在以后,这里面每个点在它之前的概率为0.5 也就是针对当前点,课变序列式呈对称态势的,所以最终期望是在中间 即:ret[u]=(n-son[u]-ancestor[u])/2+depth[u];这里的son[u]包括u #include <cstdio> #include…
题目链接 题意:要在m个数里面选n个数, 要求这n个数的差值要最小 题意在hint里很清晰了 这道题从题意到题目本身都没有什么trick 写这道题完全是为了用一下#include <numeric>里面的两个小朋友: adjacent_difference 求相邻数的差 && accumulate 求和 p.s.边界要注意,都是左闭右开 ], b[], c[]; int main() { int n, m; while(~scanf("%d%d", &…
http://codeforces.com/problemset/problem/696/B (题目链接) 题意 给出一棵树,随机dfs遍历这棵树,求解每个节点的期望dfs序. Solution 考虑对于节点u,其某个儿子节点v的期望是多少. 首先,节点u的儿子的dfs的顺序是其儿子数son[x]的全排列.考虑在排列中有多少个节点在v的前面,不妨设x排在v的前面,那么满足的排列数为:${P_n^{n-2}}$,于是x对v的期望的贡献为:$${\frac{P_n^{n-2}×size[x]} {P…
题目链接:https://codeforces.com/problemset/problem/191/A 题意: 给出 $n$ 个小写字母组成的字符串,两个字符串如果前者的最后一个字母与后者的首字母相同,那么两者可以连接, 同时要求最后得到的一个长字符串的首尾字母也要相同,求最长的满足要求的字符串的长度是多少. 题解: 这个DP蛮有意思的. 记 $f[x][y]$ 为从第一个字符串到当前字符串,字母 $x$ 到字母 $y$ 的最长字符串的长度. 这样,对于当前的字符串 $s_i$,状态转移可以枚…
A. Puzzles Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. S…
题目链接: B. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between t…
D. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. C…
D. Puzzles Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city…
期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是随机的.所对应的子树的dfs序也会不同.输出每个节点的dfs序的期望   思路: 分析一颗子树: 当前已知节点1的期望为1.0 ->anw[1]=1.0 需要通过节点1递推出节点2.4.5的期望值 1的儿子分别是2.4.5,那么dfs序所有可能的排列是6种: 1:1-2-4-5  (2.4.5节点的…
题目的大意是,给你 m 个数字,让你从中选 n 个,使得选出的数字的极差最小. 好吧,超级大水题.因为要极差最小,所以当然想到要排个序咯,然后去连续的 n 个数字,因为数据不大,所以排完序之后直接暴力就OK了. 附AC代码: 1: #include <stdio.h> 2: #include <math.h> 3: #include <iostream> 4: #include <cstdarg> 5: #include <algorithm>…
A,给一棵完全二叉树,第一个操作,给两个点,两点路径上的所有边权值都增加w,第二个操作,给两个点,求两点路径上的所有边权值和. 我看一眼题就觉得是树链剖分,而我又不会树链剖分,扔掉. 后来查了题解,首先数据范围是1e18不可能是树剖,其次完全二叉树啊!不是普通的树啊!!sb... //我做过此题,没做出来,被学弟教会..虽然我做的题少,但我一向觉得至少自己做过的题都是记得的...但是.... #include <algorithm> #include <iostream> #inc…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads…
题目 Source http://codeforces.com/problemset/problem/717/G Description You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the un…
前面说点什么.. 为了完成日常积累,傻逼呵呵的我决定来一发codeforces 挑水题 泛做.. 嗯对,就是泛做.. 主要就是把codeforces Div.1的ABCD都尝试一下吧0.0.. 挖坑0.0.. Codeforces Round #360 A. NP-Hard Problem 就是一个二分图染色,判断是否为二分图而已.. B. Remainders Game 题意:有一个未知的\(x\)和已知\(x\ mod\ c_i\)的值,问是否能确定\(x\ mod\ k\)的值 考虑一下中…
B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be…
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/556/problem/B Description Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famou…
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Noura Boubou is a Syrian volunteer at ACM ACPC (Arab Collegiate Programming Contest) since 2011. She graduated from Tishreen Un…
CodeForces Round 199 Div2   完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿. My submissions     # When Who Problem Lang Verdict Time Memory 4434550 Sep 9, 2013 11:57:20 AM OIer E - Xenia and Tree GNU C++ Accepted 842 ms 4260 KB 4434547 Sep 9, 2013 11:56:11 AM OIer…
Puzzles Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city num…
A题: A题题目链接 题目描写叙述: 位运算 TimeLimit:1000MS  MemoryLimit:65536KB 64-bit integer IO format:%I64d Problem Description 已知一个包括 n 个元素的正整数集合S.设 f(S) 为集合S中全部元素的异或(XOR)的结果. 如:S={1,2,3}, 则 f(S) = 0. 给出集合S,你须要计算 将全部f(s)进行异或后的值, 这里 s⊆S. Input 多组測试数据.第一行包括一个整数T(T≤20…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, pu…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…