csu - 1538: Shopping (贪心)】的更多相关文章

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走,走到n+1点需要最少步数.思路是:因为走某些点时,必须先走另外一点,所以可以用贪心算法,将限制条件可以看成区间,求出它们的并集,如下图: #include<iostream> #include<algorithm> #include<cstring> #include&l…
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop…
题意:给定n个线段,问能不能把x,y,z个长度为1,2,3的线段不重合地放进去. 思路:首先如果n个线段长度比要放的长度之和小,则无解,否则先考虑放2和3,如果2和3放下了1肯定可以放下(这是显然的).于是我们贪心先把n个线段放满长度为3的线段,然后再考虑删去长度为3的线段来放长度为2的线段,删的时候要选择删去以后空闲的线段长度最多的删,比如某个线段本身有1的空闲线段,这时如果删去一条放在上面的长度为3的线段,则空闲线段变为4,这种情况优先删,其它情况次之.实现上采用优先队列,保存每个线段的长度…
题意:给定 n 个商店,然后有 m个限制,去 c 之前必须先去d,问你从0到n+1,最短路程是多少. 析:我们我们要到c,必须要先到d,那么举个例子,2 5, 3 7,如果我们先到5再到2,再到7再到3,那么3-5这个区间我们走了4次,如果我们先到7再到2, 那么就只走了3次,这很明显是最优的,所以我们把能合并的区间都合并起来,然后再一块计算. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include…
A    Knight 留坑. B    Tree 思路:两次树形DP,但是要考虑0没有逆元 可以用前缀后缀做 #include <bits/stdc++.h> using namespace std; #define N 1000010 #define ll long long ; int n; ll dp[N], dp2[N]; ll prefix[N], suffix[N]; vector <int> G[N]; void Init() { ; i <= n; ++i)…
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<=105)个询问,每次交换x,y位置上的括号后这个序列是否还合法,询问之间不影响. 题目思路: [贪心] 首先可以肯定,交换相同的括号是不会有影响的.把后面的'('和前面的')'交换也不会有影响.所以只用考虑把前面'('和后面的')'交换 而这时要满足x,y之间的所有位置i不会存在,1~i个括号中左括号数少于右…
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n, 2),显然不行. 考虑每一个数,显然,从最高位开始,如果它能和某一个数xor,让最高位为1,效果肯定是最佳的.其次考虑次高位,以此类推. 简单说,就是x的某一位,如果能找到某些数与x这一位xor为1,则考虑这些数,然后比较下一位:否则,就直接考虑下一位.起始从最高位开始考虑. 在这种贪心策略下,用字…
题目传送门 /* 题意:有n个商店排成一条直线,有一些商店有先后顺序,问从0出发走到n+1最少的步数 贪心:对于区间被覆盖的点只进行一次计算,还有那些要往回走的区间步数*2,再加上原来最少要走n+1步就是答案了 详细解释:http://blog.csdn.net/u013625492/article/details/45640735 */ #include <cstdio> #include <algorithm> #include <cstring> #include…
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的鱼的个数,之后总是选最大的就好了,这里我是直接变的f数组,所以最后一定不要忘了在赋值回来 [时间复杂度]\(O(n^2k)\) &代码: #include <cstdio> #include <bitset> #include <iostream> #include…
1749: Soldiers ' Training Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 37  Solved: 18[Submit][Status][Web Board] Description In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Le…
1757: 火车入站 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 209  Solved: 51[Submit][Status][Web Board] Description 火车站人们总是在站台等待列车进站,一个站台有火车停留的时候就不能有其他火车进入,今天有n辆火车经过,已知它们进站时间Si以及出站时间Ti,进站时间到出站时间之间火车必须有一个站台给它停靠,问让所有火车都能按时停靠,至少要安排多少个站台给这些火车 Input 第一行输入一个正…
Portal: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1345  http://codeforces.com/gym/100803/attachments  A题 好题! 坑不多,切入比较难 一开始的想法是暴力,由于求得是最小解且此图太大无边界,所以不能DFS,首先想到BFS 解法1 BFS+STL queue #include<iostream> #include<algorithm> #include&…
正题 题目链接:https://www.luogu.com.cn/problem/AT3949 题目大意 长度为\(L\)的坐标轴上,给出\(n\)个点,每个点\(x_i\)需要购物\(t_i\)的时间,一辆车在\(0\sim L\)折返跑,求从\(0\)出发购物完回到\(0\)的最短时间. \(n\in[1,3\times 10^5],L\in[1,10^9]\),输入的\(x_i\)单调递增. 解题思路 挺奇妙的题目,\(WC2021\)讲课的题. 首先每个\(t_i\)先\(\%\)上一个…
#include <bits/stdc++.h> using namespace std; ; int fa[maxn]; int main(){ int n, m; scanf("%d%d", &n, &m); ; i <= n+; i++) fa[i] = i; ; i <= m; i++){ int x, y; scanf("%d%d", &x, &y); fa[x] = max(fa[x], y); }…
还是给你石头n枚,每一枚石头有两个值a和b,每取一个石头,除了这块石头其余所有的石头的a就都减去这个石头的b,问你取了的石头的a的总和最大可以为多少? 先按B从大到小排序 然后DP: 取的话:dp[i][j]=dp[i-1][j-1]+a[i]-b[i]*(j-1) 注意是j-1 不取的话:dp[i][j]=dp[i-1][j]; #include<iostream> #include<cmath> #include<cstdio> #include<sstrea…
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For e…
Parenthesis Problem Description: Bobo has a balanced parenthesis sequence P=p1 p2-pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi swapped. Note that questions are individual so that they have no affec…
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goo…
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned into a cook, was shopping for food. Clarke has bought n food. The volume of the ith food is vi. Now Clarke has a pack with volume V. He wants to carry…
Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17622    Accepted Submission(s): 10252 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he…
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 题解: 关键是怎么处理长度为1的长方形.当长度为1的长方形的个数cnt>=2时,怎么把这些长方形分成两组,使得这两组的高度差最小,即最接近H/2.一开始用贪心做,结果wa了.因为贪心出来的不一定是最优,于是就想到了用dp.dp出H/2最大能够容纳的高度.然后再取 H-dp[H/2]. 代码如下: #include <iostream> #include <cst…
题目:https://jzoj.net/senior/#main/show/5461 贪心,原来想了个思路,优先选优惠价最小的 K 个,然后其他按原价排序遍历: 如果当前物品没选过,原价选上,如果选过,考虑把它换成原价,然后把优惠价最小的下一个选上: 但这样做是75分,没考虑 替换没选过的物品 和 比较替换后是否更优: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&…
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][Status][Discuss] Description FJ打算带他的N(1 <= N <= 30,000)头奶牛去参加一年一度的“全美农场主大奖赛”.在这场比赛中,每个参赛者都必须让他的奶牛排成一列,然后领她们从裁判席前依次走过. 今年,竞赛委员会在接受队伍报名时,采用了一种新的登记规则:他们把所…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15564    Accepted Submission(s): 6405 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a…
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g…
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][Status][Discuss] Description 与很多奶牛一样,Farmer John那群养尊处优的奶牛们对食物越来越挑剔,随便拿堆草就能打发她们午饭的日子自然是一去不返了.现在,Farmer John不得不去牧草专供商那里购买大量美味多汁的牧草,来满足他那N(1 <= N <= 100,…
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…
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Status][Discuss] Description 给定一个长度为n的序列a[1],a[2],...,a[n],请将它划分为m段连续的区间,设第i段的费用c[i]为该段内所有数字的异或和,则总费用为c[1] or c[2] or ... or c[m].请求出总费用的最小值. Input 第一行包含…
1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 的堆上:在编号为 N 的堆上取的纸牌,只能移到编号为 N-1 的堆上:其他堆上取的纸牌,可以移到相邻左边或右边的堆上. 现在…
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ]; int n,m,d,l,ans; int main() { scanf("%d%d%d%d",&n,&m,&d,&l); ;i<=n;i+…