[CF1303D] Fill The Bag - 贪心】的更多相关文章

Solution 考虑从低位往高位贪心,设当前在处理第 \(i\) 位,更低位剩余的部分一共可以拼出 \(cnt\) 个 \(2^i\) 如果 \(n\) 的这一位是 \(1\) ,那么这一位就需要处理 如果 \(cnt>0\),那么直接从 \(cnt\) 里拿一个,答案不变 否则,暴力向更高位找到最小的那一个,比如它在 \(j\) 位,那么将 \(a_j\) 减 \(1\),同时将 \(a_{j-1},...,a_{i}\) 都加上 \(1\),并且答案增加 \(j-i\) 做完每一位后,维护…
\[ \texttt{Preface} \] 不开 long long 见祖宗. \[ \texttt{Description} \] 你有一个 \(n\) 码的袋子,你还有 \(m\) 个盒子,第 \(i\) 个盒子的尺寸是 \(a_i\) ,这里的每一个 \(a_i\) 都是 \(2\) 的非负幂整数. 你可以把盒子分成大小相等的两部分.你的目标是完全装满袋子. 例如 \(n=10,a=[1,1,32]\) ,那么你必须把 \(32\) 码的盒子分成 \(16\) 码的两部分,然后把 \(1…
With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are asked…
题目 With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are ask…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515 题意 n*n矩阵中填入大写字母,n <= 10,要求从上到下从左到右字母序最小,相邻格子字母不同 思路 如刘书思路,状态比较小,不会导致矛盾. 感想 1. 状态较小 代码 #include <algorithm> #include <cassert>…
1e18对应2进制有58位,可以直接暴力模拟,因为读入的数都是2次幂,__builtin_ctz这个内置gcc函数可以算出二进制下末尾有几个0,读入时统计,然后从n的最低位开始判断,注意每次升位的时候如果有2个相同的就要向上一位进位,当拆掉比他大的数时,必定对比他大的位各个产生一个1,因为>>1 #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long lon…
题解:注意这里的数组a中的元素,全部都是2的整数幂.然后有二进制可以拼成任意数.只要一堆2的整数幂的和大于x,x也是2的整数幂,那么那一堆2的整数幂一定可以组成x. 思路:位运算,对每一位,如果该位置i是1的话,先考虑从0到该位置的,数组a的和,如果比(1<<i)的话,那么可以拼接,否则的话,需要从高位向下除,也就是从i+1位到58位,找到第一个再某一位置j上不为0的数 然后需要降j-i次幂.然后从j~i,每一位上数的个数都要+1.并且累加答案ans+=j-i; #include<bit…
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fallen Lord(sort(a+1,a+1+n,greater<int>()); 真好用) P4161 [SCOI2009]游戏 P1707 刷题比赛 2021-10-12 CF1573A Countdown P2717 寒假作业 P7868 [COCI2015-2016#2] VUDU P1660…
A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int main(){ int t;cin>>t; while(t--){ string s;cin>>s; ,f2 = ; ; ; ;i<s.length();i++){ '){ ) { ans+=cnt; cnt = ; f1 = ; } ) f1 = ; } else{ ) c…
记录 Codeforces 2019年12月19日到 2020年2月12日 的部分比赛题 Educational Codeforces Round 82 (Rated for Div. 2) D Fill The Bag 给出m(≤1e5)个盒子,盒子的大小是2的幂次.可以选择把一个盒子分成大小相同的两部分,问最少执行几次分盒子的操作,可以装满大小为n(≤1e18)的背包. 把n转化为二进制,代表可以由若干种2的幂次的盒子各一个装满.从小往大贪心地使用已有的盒子,不足时把第一个比它大的盒子分开.…
A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegm…
比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \(1\) 到最后一个 \(1\) 中间的 \(0\) 全部去掉,也就是它们之间 \(0\) 的个数,那么就顺序.逆序扫一遍就出来了. 代码详解: 点击查看代码 #include<bits/stdc++.h> using namespace std; int main(){ int t; cin&g…
With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are asked…
1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Guochuan With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to fin…
1033 To Fill or Not to Fill (25 分)   With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may…
//贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include<algorithm> struct Node { float p, d; }; bool cmp(Node a, Node b) { return a.d < b.d; } int main() { Node node[]; float Cmax, D, Davg, distance, pr…
填充正方形(Fill the Square, UVa 11520) 在一个n×n网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多种填法,则要求按照从上到下.从左到右的顺序把所有格子连接起来得到的字符串的字典序应该尽量小. [输入格式] 输入的第一行为测试数据组数T.每组数据的第一行为整数n(n≤10),即网格的行数和列数:以下n行每行n个字符,表示整个网格.为了清晰起见,本题用小数点表示没有填字母的格子. [输出格式]…
转自:https://www.cnblogs.com/XBWer/p/3866486.html With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas…
题目如下: With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are…
PAT-A的最后一题,最终做出来了... 是贪心,通过局部最优获得全局最优. 1. 将加油站按距离升序排序 2. 记录当前所在的加油站index,存有的汽油,花费.向后遍历全部 该站可抵达的加油站 3. 遍历中有两种情况: 1) 若发现油价比index更低的站next: 立即跳到该站(此时可能须要加油),不再继续遍历 -- 由于即使想要到达next后面的站,能够通过在next站购买更廉价的汽油来实现 2) 没有发现油价比index更低的站,则选择全部站中油价最低的站作为next: 此时考虑能否通…
题目描写叙述: With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You ar…
题意: 输入四个正数C,DIS,D,N(C<=100,DIS<=50000,D<=20,N<=500),分别代表油箱容积,杭州到目标城市的距离,每升汽油可以行驶的路程,加油站数量.接下来输入N行数据,每行包括一个小数代表该加油站每升汽油的价格和该加油站距离杭州的距离.输出杭州到该城市的最小加油花费,如果到不了的话输出离开杭州的最远路程. 思路: 每次到一个加油站时都把油箱加满,如果加油站i油箱加满所能行驶的范围内有加油站j油价比i便宜,那么j位置的花费就为i位置的花费减去(油箱加满…
2020-01-20 22:32:28 问题描述: 问题求解: 双指针 + 贪心. public int bagOfTokensScore(int[] tokens, int P) { Arrays.sort(tokens); int res = 0; int curr = 0; int l = 0; int r = tokens.length - 1; while (l <= r) { if (P >= tokens[l]) { curr += 1; P -= tokens[l]; l++;…
题目地址:http://ac.jobdu.com/problem.php?pid=1437 题目描述: With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different…
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she…
Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1555    Accepted Submission(s): 657 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Ze…
Problem F: Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrictions The i-th rook can only be placed within the rectangle given by its left-upper corner (xli, yli) and its right-lower corner (xri…
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots…
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned into a game player of minecraft. On that day, Clarke set up local network and chose create mode for sharing his achievements with others. Unfortunately…
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 513 Accepted Submission(s): 142 Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia…