codeforces A. Wrong Subtraction】的更多相关文章

A. Wrong Subtraction time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or…
手动博客搬家: 本文发表于20181212 09:37:21, 原地址https://blog.csdn.net/suncongbo/article/details/84962727 呜啊怎么又是数学了啊...数学比例\(\frac{16}{33}=0.4848\) orz yhx-12243神仙 题目链接: https://codeforces.com/contest/947/problem/E 题意: 有一个\([0,n]\)的随机数\(x\)初始为\(i\)的概率为\(p_i\). \(m…
Codeforces 题目传送门 & 洛谷题目传送门 神仙题 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 首先考虑最朴素的 \(dp\),设 \(dp_{z,i}\) 表示经过 \(z\) 次操作后剩下的数为 \(i\) 的概率,那么显然有 \(dp\) 转移方程 \(dp_{z,i}=\sum\limits_{j\ge i}dp_{z-1,j}·\dfrac{1}{j+1}\). 边界条件 \(dp_{0,i}=p_i\) 直接递推显然不行,考虑优化,我们记 \(F_z(x)…
题目网址:http://codeforces.com/contest/977/problem/A 题解:给你一个数n,进行k次变换,从末尾开始-1,512变成511,511变成510,510会把0消掉.(看Note应该都能看懂的吧~) 方法:水题...把数字用字符串读入,遇到末尾为0的情况就把字符串长度-1,不然就-1.然后len<=0的情况就输出0(不知道为什么不用<0就可以过了,可能不会出现这样的情况?),反之按长度一个个输出即可~ #include<cstdio> #incl…
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减去最小值,输出这个最小值,k用不完用0来补. 题解: 考虑到重复的数会被一起减去,所以我用了个set来存放这n个数,然后用个累加器记录下减去了多少最小值,把数取出来时减去这个累加器就好了,最后用0来补. 代码如下: #include <bits/stdc++.h> using namespace…
https://zh.wikipedia.org/wiki/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95 取模也是一样的,就当多减几次. 在欧几里得最初的描述中,商和余数是通过连续的减法来计算的,即从rk−2中不断减去rk−1直到小于rk−1.一个更高效的做法是使用整数除法和模除来计算商和余数: rk ≡ rk−2 mod rk−1 在欧几里得定义的减法版本,取余运算被减法替换 while (b!=0) { if (a>b) a=a-b; else…
B. Weird Subtraction Process   time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have two variables a and b. Consider the following sequence of actions performed with these variables: If …
链接: https://codeforces.com/contest/1238/problem/A 题意: You are given two integers x and y (it is guaranteed that x>y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y? Recall that a pr…
https://codeforc.es/contest/1088/problem/B 模拟即可. #include<bits/stdc++.h> using namespace std; typedef long long ll; priority_queue<int, vector<int>, greater<int> >pq; int sumsub = 0; int main() { #ifdef Yinku freopen("Yinku.in…
传送门 样例(x): 8 15 16 17 19 27 36 29 33 结果(t1) 15 15 16 18 26 35 28 32 思路:我们可以把最左端和最右端当做两个水龙头,每个水龙头流量的上限就是a[x]. 我们通过贪心,我们尽可能的使用左边的流量,例如样例(x),我们流到第二个点的时候,我们发现左边的流量不可能在第二个点流出16单位流量,说明这个点需要右边流量的补充,而且只需要补充1单位的流量,那有人会问,为什么不多流过来一些呢,这里就是贪心的想法,我左边边能完成的事就不劳烦你右边,…
题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解:贪心,我们优先考虑从左边减,如果当前项比后一项大\(a_i>a_{i+1}\),那么我们一定可以从左边减,使得这个区间变为\(0\),否则,光从左边减是不能使后一项元素变为\(0\)的,此时我们就要从右边减,即某尾到这项这段区间减去差值\(a_{i+1}-a_i\),我们可以直接累加这些差值,如果遍…
题目链接:http://codeforces.com/contest/493 A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second y…
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The most popular one is the…
D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/132/problem/D Description Shakespeare is a widely known esoteric programming language in which programs look like plays by Shakespea…
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just pu…
Codeforces Round #525 (Div. 2) 哎,忍不住想吐槽一下,又要准备训练,又要做些无聊的事,弄得我都想退出了. 好好的训练不好么???? 只能做出两道水题,其实C题,感觉做出来了,差几分钟,不能提交了,明天交一发试试吧. 题目一览表 来源 考察知识点 完成时间 A Ehab and another construction problem cf 签到?? 2018.12.4 B Ehab and subtraction cf 签到?? 2018.12.4 C Ehab a…
C. Vasya and Basketball 题目链接:http://codeforces.com/problemset/problem/493/C time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya follows a basketball game and marks the distances from whi…
1076A---Minimizing the String[字符串] http://codeforces.com/contest/1076/problem/A 题意: 删掉字符串中的一个字符使得得到的字符串是字典序最小的一种. 思路: 从头到尾找到第一个字符他比他后面的一个字典序要大,那就是要删掉的. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include&…
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直接写,手速题,没啥好说的 B. Two-gram 题意 求出现次数最多的连续两个字符 还是签到题,我居然很麻烦地用了map,= =算了,思路畅通都无所谓了 #include <iostream> #include<stdio.h> #include<algorithm> #…
目录 Contest Info Solutions A. Prime Subtraction B. Kill 'Em All C. Standard Free2play D. AB-string E. Keyboard Purchase F. The Maximum Subtree Contest Info Practice Link Solved A B C D E F G 6/7 O O O O Ø Ø - O 在比赛中通过 Ø 赛后通过 ! 尝试了但是失败了 - 没有尝试 Solution…
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # include <bits/stdc++.h> int main() { int x; scanf("%d", &x); for(int i = 1; i <= x; i++) for(int j = 1; j <= x; j++) if((i % j == 0) &…
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数小于 \(4n\) . 题解 因为不互质所以 \(gcd\) 至少为 \(2\),又为了避免相互整除,可以从倒着较大的 \(4n\) 开始构造. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with…
上一次我们拿学校的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…