[Codeforces 10E] Greedy Change】的更多相关文章

Brief Introduction: 给你一些种类的硬币,用最少的硬币数表示X 求最小的使贪心算法错误的X Algorithm: 一道论文题,<A Polynomial-time Algorithm for the Change-making Problem> 证明先挖个坑,以后再填 感性猜想,我们可以构建出这样一个算法: 对于一种币值A,我们找出一个略大于A仅用币值不小于B且小于A的货币表示的值X,使得贪心算法在使用A后要用更多零碎的货币 这样,只要枚举A.B,找出最小的这样的值即可.存在…
Greedy Change time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the ap…
洛谷 Codeforces 看到题解那么少就来发一篇吧-- 思路 看完题目一脸懵逼,感觉无从下手. 莫名其妙地想到笛卡尔树,但笛卡尔树好像并没有太大作用. 考虑把笛卡尔树改一下:每个点的父亲设为它的右边第一个大于它的位置. 这时突然发现一个很好的性质:搞答案时每次从右边加入一个点\(x\)时,以\(x\)的子树中的一个点为起点的长度全都加一. 那么按dfs序建线段树维护区间和.区间加.单点修改为-INF(从左边删点)即可. 代码 #include<bits/stdc++.h> clock_t…
对于$w$的表示方案,可以用序列描述,即$x_{i}$表示第$i$种货币的数量 贪心策略得到的方案即是(对应序列)字典序最大的方案,并定义最优策略得到的方案为在最小化货币总数的基础上,(对应序列)字典序最大的方案 记$g_{w}$和$f_{w}$分别为贪心和最优策略下$w$的表示方案,问题即求最小的$w$满足$\sum_{i=1}^{n}g_{w,i}>\sum_{i=1}^{n}f_{w,i}$ (以下方案比较均按照字典序,性质1-4均比较显然,可以简单思考后跳过证明) 性质1:$\foral…
Socks Problem Description: Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her…
题目链接:http://codeforces.com/problemset/problem/379/C 题目意思:有n个users,每个user都有自己想升的rating.要解决的问题是给予每个人不同的rating,使得每个人rating不比他期望的rating小,即 安排的rating >= 他自己的希望的rating,还有一个条件就是 总rating之和要最小. 要想使得总rating最少,那么安排的rating要尽可能小.把rating从小到大排序.对最小的rating值当然就给予这个值,…
https://codeforces.com/contest/911/problem/G 没想到线段树合并还能这么搞.. 对每个权值建一个线段树(动态开点),如果权值为k的线段树上第i位为1,那么表示a[i]=k:如果权值为k的线段树上第i位为0,表示a[i]≠k 改变权值的时候,就是把[l,r]分解成多个线段树上的区间:对于每个分解出的区间,分别在权值为x的线段树上和权值为y的线段树上找到对应的节点,设某个区间找到的节点为a,b,则把b子树合并到a上 注意!要特判x==y时跳过操作 最后枚举一…
A. Payment Without Change You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0≤x≤a) coins of value n and y (0≤y≤b) coins of value 1, then the total v…
G. Castle Defense time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Thr…
题目链接 \(Description\) 给定两个长为\(n\)的数组\(x_i,y_i\).每次你可以选定\(i,j\),令\(x_i=x_i\ \mathbb{xor}\ x_j\)(\(i,j\)可以相等).要求若干次操作后使得\(x\)变成\(y\),输出方案.操作次数不能多于\(10^6\),无解输出\(-1\). \(n\leq10^4,\ 0\leq x_i,y_i\leq10^9\). \(Solution\) 考虑异或的两个基本性质: 异或是可逆的,逆运算就是它本身. 可以交换…
我们从右往左滑动区间, 假设dp[i]表示i为左端点时的最大长度, 通过观察可以发现, 每添加一个点, 该点$dp$值=它右侧第一个比它大位置处$dp$值+1, 但是每删除一个点会将所有以它为根的$dp$值全-1, 所以可以根据转移建一棵树, 需要有单点查询单点更新以及树链加, 可以用线段树维护dfs序$O(logn)$实现, 或者直接树剖$O(nlog^2n)$ #include <iostream> #include <algorithm> #include <cstdi…
链接 大意: 给定序列, 每次操作将区间[l,r]中的x全改为y, 最后输出序列 权值范围比较小, 对每个权值开一颗线段树, 每次将x合并到y上即可 #include <iostream> #include <algorithm> #include <cstdio> #define REP(i,a,n) for(int i=a;i<=n;++i) #define mid (l+r>>1) #define lc (o<<1) #define…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举那个人收到了几次糖i. 最好的情况显然是其他人都只收到i-1次糖. 然后这个人刚好多收了一次糖 也即 (i-1)kx + x <= n 显然x越大越好. 那么直接令\(x=\frac{n}{( (i-1)*k+1)}\)就好 如果x>M了 那么令x = M; 但这个时候. 要判断一下改变之后的x,按照顺序分的时候是否还能满足这个人收到i次糖. 如果不能收到i次糖的话.跳过.不能统计答案. [代码] #include <…
作为DIV2的D题来讲,这个题目不算难. 题目大意:再规定的时间内寻找宝藏,第i个宝藏的位置为a*x(i-1)+b,a*y(i-1)+b.然后给出初始位置xs,ys和时间t让求再时间t内能够寻找到多少宝藏. 题解: 两相邻的宝藏的坐标差一定是最小的.所以答案一定是连续的一组坐标.注意数据范围x的范围是2e16,a最小是2,所以最多也就60多个宝藏,直接暴力起点终点就行. #include<bits/stdc++.h> using namespace std; typedef long long…
Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... FST!! 不,这次是skip,A题gi了(从小号蒯来没改),其它就都会skip...... 大号被小号skip,大号还300多名(没WA),做不得卵声.结果小号rank408,+133raiting 恭喜LCFrank10,+279raiting 为了表示我被skip的愤怒,我决定用大号打Vit…
A,B,C傻逼题,就不说了. E题: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; ,mod=; typedef long long int64; ]; int64 a[maxn],s1[maxn<<],s2[maxn<<]; struct…
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ *Author* : Ray(siludose) *Created Time* : 2016��10��24�� ����һ 15ʱ00��28�� **Problem** : /media/ray/708898B888987E72/Users/Administrator/Desktop/2016…
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard input output: standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are …
C. Socks time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them…
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as foll…
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of sizen × m and consists of blocks of size 1 × 1. Each block o…
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length…
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The New Year holidays are over, but Resha doesn't want to throw away the N…
C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented a…
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted bla…
地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Memory is performing a walk on the two-dimensional plane, starti…
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m g…
Unusual Product Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. T…
Gravity Flip Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, s…