UVALive 4225 Prime Bases 贪心】的更多相关文章

Prime Bases 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2226 Descriptionww.co Given any integer base b >= 2, it is well known that every positive integer n can be uniquely rep…
Prime Bases Problem Description Given any integer base b >= 2, it is well known that every positive integer n can be uniquely represented in base b. That is, we can write n = a0 + a1*b + a2*b*b + a3*b*b*b + ... where the coefficients a0, a1, a2, a3,…
题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known that every positive integer n can be uniquely represented in base b. That is, we can write n = a0 + a1 ∗b + a2 ∗b∗b + a3 ∗b∗b∗b + ... where the coeffi…
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4924 Prime Switch Time limit: 1.000 seconds 问题描述 There are lamps (uniquely numbered from 1 to N) and K switches. Each switch has one p…
Prime Switch 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4924 Description There are lamps (uniquely numbered from 1 to N) and K switches. Each switch has one prime number written…
按照题意的要求逐渐求解: #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ]={,,,,,,,,}; ][]={","2*3","2*3*5","2*3*5*7","2*3*5*7*11","2*3*5*7*11*13", "2*3*5*7*11…
Robots 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/K Description http://7xjob4.com1.z0.glb.clouddn.com/168817810b54cfa4ffaebf73d3d1b0c5 Input The input consists of multiple test cases. First line contains a single integer t indicating…
题目连接:3971 - Assemble 题目大意:有若干个零件, 每个零件给出的信息有种类, 名称, 价格, 质量,  现在给出一个金额, 要求在这个金额范围内, 将每个种类零件都买一个, 并且尽量让这些零件中质量最小的越大, 输出质量最小的值. 解题思路:首先可以用二分搜索确定质量, 然后在搜索的过程中要判断这个质量是否能被满足, 判断函数可以用贪心, 在每一类的零件中选择价格最低且质量大于等于当前质量的零件.(事先按照价格大小排序). #include <stdio.h> #includ…
题目链接:传送门 [题意]有n个灯,m个开关,灯的编号从1~n,每个开关上有一个质数,这个开关同时控制编号为这个质数的倍数的灯,问最多有多少灯打开. [分析]发现小于根号1000的质数有10个左右,然后大于根号1000的质数所控制的灯是不会重叠的,所以我们状压枚举小于31的质数,然后贪心后面的. #include <cstdio> #include <map> #include <algorithm> #include <vector> #include &…
E - Maximum Square Time Limit:4500MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4867 Description Given an NxM matrix of all 1s and 0s, find the largest submatrix which is a square containing all 1s. Input Ther…
题意: 给定n个队伍, 然后A房间有a个气球, B房间有b个气球, 然后给出每个队伍所需要的气球数量和到A B房间的距离, 求把气球全部送到每个队伍的最短距离. 分析: 在气球充足的情况下, 那么我们对于每个队伍, 肯定是哪个房间近就取哪个房间的气球. 但是题目中气球的数目有限, 所以很有可能出现某个时刻第i个队伍到A比较近, 但是A没有气球了, 只能去B拿的这种情况.这样的损失就是他们的距离差. 所以猜想是先把到A和到B距离差较大的队伍先满足了, 这样就能降低损失, 有这种贪心的思想应该就能求…
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its…
题目连接:2322 Wooden Sticks 题目大意:给出要求切的n个小木棍 , 每个小木棍有长度和重量,因为当要切的长度和重量分别大于前面一个的长度和重量的时候可以不用调整大木棍直接切割, 否则要进行调整.现在要求求出一个序列, 使得调整的次数最少, 输出调整的次数. 解题思路:将n个小木棍先按照 长度和重量的大小排序,然后按照顺序将小木棍分堆,可入堆的要求是长度和重量大于当前这个堆的长度和重量,入堆之后, 要将新的木棍的属性赋值个这个堆, 如果当前所有堆都没法放下这个木棍, 就得单独放成…
题目大意: 有n支队伍,每两支队伍打两场比赛(主客场各一次),胜得3分,平得1分,输不得分,比赛结束之后会评选出一个梦之队,梦之队满足以下条件:进球总数最多,胜利场数最多,丢求总数最少,三个都不能并列,求梦之队的最低排名 解析来自:https://blog.csdn.net/l123012013048/article/details/44001543 分析 1.让梦之队的胜利场的进球总数达到无穷大(当然这是不可能的),输的场都是进0球对方队伍进1球,平的场都是0:0的得分,这样即使梦之队只赢一场…
题意:n个格子,m个球,让你把球放入某些格子里,使得所有有球的格子之间的距离(abs(i-j))均为素数 ,让你输出方案数. 只占一个格子或者两个格子显然可行. 占有三个格子的情况下,则必须保证其中两者的间距为2,另两者的间距为一个+2以后仍为素数的素数.这个可以预处理. 占有四个格子的情况下,间距只有一种合法情况 2 3 2. 其他情况都不合法. 确定了占有的格子数,尝试放球保证没有一个格子为空的时候,可以用挡板法. #include<cstdio> using namespace std;…
题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i  在pos 位置,那么如果 (pos-i)*2+i-1 <= n,那么可以操作一次换过来, 如果不行再换一种,如果他们之间元素是偶数,那么交换 i - pos,如果是奇数,交换 i - pos+1,然后再经过一次就可以换到指定位置. 代码如下: #pragma comment(linker, "/STACK:1…
先从中找出性能最好的那个数, 在用钱比較少的去组合,能组出来就表明答案在mid的右边,反之在左边, #include<string.h> #include<map> #include<stdio.h> #include<iostream> #include<algorithm> using namespace std; map<string,int> vic;//以字符映射数字 int end,start; int num; int…
题目描述 参与考古挖掘的小明得到了一份藏宝图,藏宝图上标出了 \(n\) 个深埋在地下的宝藏屋, 也给出了这 \(n\) 个宝藏屋之间可供开发的 \(m\) 条道路和它们的长度. 小明决心亲自前往挖掘所有宝藏屋中的宝藏.但是,每个宝藏屋距离地面都很远, 也就是说,从地面打通一条到某个宝藏屋的道路是很困难的,而开发宝藏屋之间的道路 则相对容易很多. 小明的决心感动了考古挖掘的赞助商,赞助商决定免费赞助他打通一条从地面到某 个宝藏屋的通道,通往哪个宝藏屋则由小明来决定. 在此基础上,小明还需要考虑如…
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5922 题意: 给出 $N$ 个冰淇淋球,第 $i$ 个冰淇淋球大小为 $B_i$,现在已知冰淇淋球堆叠起来可组成一个冰淇淋. 对于上下相邻的两个冰淇淋球,只有上面的那个大小不…
题目传送门 /* 题意:有n个商店排成一条直线,有一些商店有先后顺序,问从0出发走到n+1最少的步数 贪心:对于区间被覆盖的点只进行一次计算,还有那些要往回走的区间步数*2,再加上原来最少要走n+1步就是答案了 详细解释:http://blog.csdn.net/u013625492/article/details/45640735 */ #include <cstdio> #include <algorithm> #include <cstring> #include…
题目传送门 /* 贪心:按照0或1开头,若不符合,选择后面最近的进行交换.然后选取最少的交换次数 */ #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <cmath> #include <vector> #include <map> #include <queue> using namesp…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=648&page=show_problem&problem=5159 In normal football games, the winner team gets 3 points, loser team gets 0 point, and if there is a drawgame, bot…
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others.One day, there is another tribe become their target. The strong tribe has decide to terminate them!!!There are m villages in the other tribe. Each vil…
题意:给定 n 个区间,让你选出最多的区间,使得每个区间不相交. 析:贪心题,贪心策略是按右端点排序,然后按着选即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #…
题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: 析:贪心策略,让大的和小的搭配,小的和大的搭配,是最优的. #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include &l…
题意:给定 n 个数,要求把其中两个分成一组,然后加和,问所有的都分好,最小数是几. 析:贪心策略,最大和是小的相加,就是最优的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <functional> #include <cstdlib> #include <cma…
Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm = b *  for some integers  a and  b  (a > 0). Determine the maximum value of xp1 + xp2 +...+ xpm for some even positive integer p. Input Each input li…
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 +...+ xm = b *  两端同时乘以根号a去计算.然后按照贪心的思想去计算. #include <stdio.h> #include <math.h> int l, r; double m, p, a, b, tmp, sum; int main() { while (sca…
补:华中VJ这个题目很多标程都不能AC了,包括我下面原本AC了的代码,再交就WA掉了,感觉是样例有问题呢-- 首先左边的是必须要选的,然后右边的需要注意,有些区间是可以舍掉的.1.区间里有两个不同的A. 2.区间里有一个A,而且这个A不是这个区间对应的A. 这个题我一开始错在了第2个判定条件上,我定义的id记录的是最后一个出现位置,不能进行判断,所以干脆在结构体里记录了他对应的A值. 舍掉后留下的区间,可以按照区间左边界排序,然后求交集即可. 总体来说,贪心的思想还是不难的,就是有一些细节需要注…
题意 等价于给一个数列,每次对一个长度为$K$的连续区间减一 为最多操作多少次 题解: 看样例猜的贪心,10分钟敲了个线段树就交了... 从1开始,找$[i,i+K]$区间的最小值,然后区间减去最小值,答案加上最小值即可... 这个思路,后来我看博客上的总结,应该是没问题的, 可是,依旧不知道线段树写的对不对..因为是假数据... #include <bits/stdc++.h> #define ll long long #define IO ios::sync_with_stdio(fals…