CodeForces 214B Hometask】的更多相关文章

本题求n个数组成的大数,要求是2,3,5的倍数. 因为是2 和5 的倍数,所以个位为 0:所以若n个数中没有0,直接输出-1: 难点就是要求为3 的倍数. 因为若某个数为3的倍数,则其各位数的和必然是3的倍数. 当n个数的和为3的倍数时从大到小输出便可: 当n个数的和不为3的倍数时,若n个数中有模3余数与和模3余数相同时,去掉其中最小的,否则去掉两个模3余数不为0且与和模3余数不同的数中最小的.若没有这些数,输出-1: 注意当结果为0时,不能输出前导0: ps:开始写了一个很复杂的代码,后来看过…
题目链接: 传送门 Hometask Time Limit: 2 seconds     Memory Limit: 256 megabytes Description Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher,…
题目链接: http://codeforces.com/problemset/problem/154/A 题意: 给你一个字符串,和若干模板串(长度为2),至少删除多少个字母,使得字符串的字串里面没有模板串. 题解: dp[i][j]表示合法子串s[0...i]的最后一位为j时的最小花费(花费指删除的字母个数) 对每一位考虑删和不删的情况: 如果删,那么它的最后一位一定为之前出现过的. 如果不删,那么s[i]就是最后一位. 考虑这两种情况的转移就可以了. 时间复杂度:O(n*26*26) 代码:…
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory limit per test:256 megabytes 问题描述 Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark fo…
Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the Engli…
链接:http://codeforces.com/contest/404/problem/A A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera is a little boy. Yesterday he got a huge Math hometask at school, so Va…
http://codeforces.com/contest/456/problem/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops. Dima thi…
Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass a test on Numbers Theory. The lecturer is so desperate about Kolya's knowledge that she gives him the same task every time. The problem is to check i…
Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 154A64-bit integer IO format: %I64d      Java class name: (Any)   Sergey attends lessons of the N-ish language. Each lesson he receives a homet…
上一次我们拿学校的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…
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is…
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概率是在正面,各个卡牌独立.求把所有卡牌来玩Nim游戏,先手必胜的概率. (⊙o⊙)-由于本人只会在word文档里写公式,所以本博客是图片格式的. Code #include <cstdio> #include <cstring> #include <algorithm> u…
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连通图)且这颗树中必须包含节点1 然后将这颗子树中的所有点的点权+1或-1 求把所有点权全部变为0的最小次数(n<=10^5) 题解: 因为每一次的子树中都必须有1,所以我们得知每一次变换的话1的权值都会变化 所以我们以1为根 现在,我们发现,如果一个节点的权值发生变化,那么他的父节点的权值一定发生变…
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个盒子…
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不同的点的数量+1) 每一次只有当子树中所有的点都已经游走过了再会向父亲走,走到每个儿子上的概率是相同的 对于每个点,求他的权的期望 (1 ≤ n ≤ 10^5) 题解: 首先我们发现,所有子树中所有的点的编号都一定比父亲要大 而且子树中的大小关系和我们访问它的顺序有关 如果对于一个节点u它的儿子为v…
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来. 每次抓老鼠和跑出来的老鼠都是随机的. 如果两个人都没有抓到白色老鼠则龙赢.王妃先抓. 问王妃赢的概率. (0 ≤ w, b ≤ 1000). 题解: 其中第一行表示为王妃拿到的白色老鼠,自然是直接退出了 第二行表示为王妃拿到了黑色老鼠,但是因为…
http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= i 的点数的概率 ans = sigma{i*(f[i]-f[i-1])} 单个f[i]直接快速幂计算 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typede…
http://codeforces.com/problemset/problem/749/E (题目链接) 题意 给出一个1~n的排列,从中等概率的选取一个连续段,设其长度为l.对连续段重新进行等概率的全排列,求排列后整个原序列的逆序对的期望个数. Solution 考虑对于每一对数${(a_i,a_j),i<j}$算贡献. 1.连续段包含${a_i,a_j}$ 不妨设${a_i<a_j}$,则只有当排列后${a_j}$再${a_i}$前面才会对答案有贡献(${a_i>a_j}$的情况同…
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…
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的概率最大. Solution 很显然的概率dp,过了样例即可AC..话说我为什么要刷B题→_→ 代码 // codeforces442B #include<algorithm> #include<iostream> #include<cstdlib> #include<…
http://codeforces.com/problemset/problem/148/D (题目链接) 题意 包中有w个白鼠,b个黑鼠.公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢.龙每画完一只老鼠,就会有另一只老鼠从包中跑出来.每只老鼠被画到以及跑出的概率相等,问公主获胜的概率. Solution 令${f_{0/1,i,j}}$表示此时公主/龙选,包中还剩i只白鼠,j只黑鼠,公主赢的概率.那么转移很显然: $${f_{0,i,j}=\frac{i}{i+j}+\frac{j}{i+j…
吐槽一句:这数据造得真强-. 题意:有一个大小为k的缓存区,每次从n种物品中按照一定的概率选取一种物品尝试放进去.同一个物品每一次选取的概率都是相同的.如果这种物品已经放进去过就不再放进去.如果缓存区满了就把放进去的时间离现在最远的物品拿出来.问10^100次后每个物品在缓冲区中的概率. 如果正着做的话似乎状态会扩展得很多而且都没什么用. 注意到最后一次放进去的一个物品肯定在缓冲区中,而第一次放进去的物品对结果几乎没有影响,这提示我们关注最后的几次放置.假如缓冲区至少有两个位置,且倒数第二个物品…
题意:给定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<…
Codeforces 566F 题目大意:给定$N$个数,任意两个数之间若存在一个数为另一个数的因数,那么这两个数存在边,求图中最大团. 分析:求一个图最大团为NP-Hard问题,一般不采用硬方法算.设$f[i]$表示数值为$i$的数的最大团,那么那么得到以下转移: $f[i]=max \{ f[j]+1 \} j|i$ //cf 566f //by Cydiater //2016.11.4 #include <iostream> #include <cstring> #inclu…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he…