为什么要今天写呢?

明天全力研究Johnson和一些奇奇怪怪的贪心

今天把能写的都写了

T1T2太水了直接上代码吧

#include<bits/stdc++.h>
#define LL long long
using namespace std;
inline int read()
{
int x=,f=;char ch;
for(ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')f=-f;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';
return x*f;
}
int n;
priority_queue<int,vector<int>,greater<int> > q1;
priority_queue<int> q2;
int main()
{
n = read();int a;
for(int i=;i<=n;i++)a = read(),q1.push(a),q2.push(a);
while(q1.size() >= )
{
int t1 = q1.top();q1.pop();
int t2 = q1.top();q1.pop();
q1.push(t1 * t2 + );
}
//cout<<q1.top()<<endl;
while(q2.size() >= )
{
int t1 = q2.top();q2.pop();
int t2 = q2.top();q2.pop();
q2.push(t1 * t2 + );
}
//cout<<q2.top()<<endl;
cout<<q1.top() - q2.top();
}

T1

#include<bits/stdc++.h>
#define LL long long
using namespace std;
inline int read()
{
int x=,f=;char ch;
for(ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')f=-f;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';
return x*f;
}
int n,m;
int a[];
int main()
{
n = read(),m = read();int ans = ,tot = ;
for(int i=;i<=n;i++)
{
a[i] = read();
tot += a[i];
if(tot > m) tot = a[i],ans++;
}
cout<<ans + ;
}

T2

T3

每个作业有一个学分和一个DDL

在DDL前完成作业可以获得相应的学分

给出每个作业的学分和DDL

求一个顺序使得学分最大

每做一项作业需要一整天

首先 比起一天浪费掉做已经达到DDL的事情

还不如用它来拿学分

于是我们把task按DDL排序

用一个数据结构变量来记录当前选了几个task

如果可以继续选task就选

选不了就找一个分最少的和当前的比一比取大的就行了

人类智慧

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<vector>
#include<algorithm>
#define LL long long
#define pii pair<int,int>
#define x(a) a.first
#define y(a) a.second
using namespace std;
inline int read()
{
int x=,f=;char ch;
for(ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')f=-f;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';
return x*f;
}
int n,now;
bool cmp(pii a,pii b){return y(a) < y(b);}
int main()
{
while(cin>>n)
{
now = ;
if(n == ){puts("");continue;}
priority_queue<pii,vector<pii>,greater<pii> > q;
pii s[];
int ans = ;
for(int i=;i<=n;i++)
{
x(s[i]) = read();
y(s[i]) = read();
}
sort(s + ,s + n + ,cmp);
for(int i=;i<=n;i++)
{
pii temp = s[i];
if(now < y(temp))
{
++now;
q.push(temp);
ans += x(temp);
}
else
{
pii tmp = q.top();q.pop();
if(x(temp) > x(tmp)){q.push(temp);ans += x(temp);ans -= x(tmp);}
else q.push(tmp);
}
}
cout<<ans<<endl;
}
}

poj1042钓鱼

(fish is me

话说发源于小朋友精心设计的游戏被电脑组的童鞋们藐杀之后非常不爽,为了表示安慰和鼓励,VIP999决定请他吃一次“年年大丰收”,为了表示诚意,他还决定亲自去钓鱼,但是,因为还要准备2013NOIP,z老师只给了他H(1<=H<=16)个小时的空余时间,假设有N(2<=n<=25)个鱼塘都在一条水平路边,从左边到右编号为1、2、3、。。。、n)。VIP是个很讲究效率的孩子,他希望用这些时间钓到尽量多的鱼。他从湖1出发,向右走,有选择的在一些湖边停留一定的时间钓鱼,最后在某一个湖边结束钓鱼。他测出从第I个湖到I+1个湖需要走5*ti分钟的路,还测出在第I个湖边停留,第一个5分钟可以钓到鱼fi,以后再每钓5分钟鱼,鱼量减少di。为了简化问题,他假定没有其他人钓鱼,也不会有其他因素影响他钓到期望数量的鱼。请编程求出能钓最多鱼的数量。

大暴力

枚举这个人最后走到的湖

把路上的时间减去

每5分钟选择鱼最多的地方钓

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x = ,f = ;char ch = getchar();
for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
for(;isdigit(ch);ch = getchar())x = * x + ch - '';
return x * f;
}
int n,h;
struct abcd
{
int fish,d,t;
bool operator < (const abcd &b)const
{
return fish < b.fish;
}
}a[];
priority_queue<abcd> q; int main()
{
int res = ;
n = read();h = read() * ;
for(int i=;i<=n;i++)a[i].fish = read();
for(int i=;i<=n;i++)a[i].d = read();
for(int i=;i<n;i++)a[i].t = read();
for(int rt=;rt<=n;rt++)
{
int temp = ;
while(!q.empty())q.pop();
int cur = h;
for(int i=;i<=rt;i++)q.push(a[i]);
for(int i=;i<rt;i++)cur -= a[i].t;
while(cur > && !q.empty())
{
abcd now = q.top();q.pop();
if(now.fish < )break;
temp += now.fish;now.fish -= now.d;
if(now.fish > )q.push(now);
cur--;
}
res = max(res,temp);
}
cout<<res;
}

环状均分纸牌

选择中位数作为起点

然后用f[i]表示要挪到i+1处的纸牌数量

那么f[i] = k - a[i] + f[i - 1]

sigma fi就是答案

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x = ,f = ;char ch = getchar();
for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
for(;isdigit(ch);ch = getchar())x = * x + ch - '';
return x * f;
}
int n,avg;
int a[],p[];
int main()
{
n = read();
for(int i=;i<=n;i++)a[i] = read(),avg += a[i];
avg /= n;
for(int i=;i<=n;i++)p[i] = avg - a[i] + p[i - ];
sort(p + ,p + n + );
int mid = p[n / + ],ans = ;
for(int i=;i<=n;i++)ans += abs(p[i] - mid);
cout<<ans;
}

暑假集训Chapter1 贪心的更多相关文章

  1. 2015UESTC 暑假集训总结

    day1: 考微观经济学去了…… day2: 一开始就看了看一道题目最短的B题,拍了半小时交了上去wa了 感觉自己一定是自己想错了,于是去拍大家都过的A题,十分钟拍完交上去就A了 然后B题写了一发暴力 ...

  2. STL 入门 (17 暑假集训第一周)

    快速全排列的函数 头文件<algorithm> next_permutation(a,a+n) ---------------------------------------------- ...

  3. HDU - 2037 今年暑假不AC 贪心(求序列中不重叠子序列的最大值问题)

    HDU2037 今年暑假不AC  贪心算法 大意: 每次测试数据输入一个n,然后输入n对的电视节目播放时间:开始时间及结束时间, 求这个人能看的最多的完整的节目数. 解题思路: 对于这道解题,是对每个 ...

  4. 暑假集训Day2 互不侵犯(状压dp)

    这又是个状压dp (大型自闭现场) 题目大意: 在N*N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. ...

  5. 暑假集训Day1 整数划分

    题目大意: 如何把一个正整数N(N长度<20)划分为M(M>=1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式. 输入格式: 第一行一个正整数T(T<= ...

  6. 暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)

    J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64 ...

  7. HDU2037 今年暑假不AC 贪心算法

    贪心算法 : 贪心算法就是只考虑眼前最优解而忽略整体的算法, 它所做出的仅是在某种意义上的局部最优解, 然后通过迭代的方法相继求出整体最优解. 但是不是所有问题都可以得到整体最优解, 所以选择贪心策略 ...

  8. 2013ACM暑假集训总结-致将走上大三征途的我

    回想起这个暑假,从开始与雄鹰一起的纠结要不要进集训队,与吉吉博博组队参加地大邀请赛,害怕进不了集训队.当时激励我月份开始接触的,记得当时在弄运动会来着,然后就问了雄鹰一些输入输出的东西,怀着满心的期待 ...

  9. [补档]暑假集训D5总结

    %dalao 今天又有dalao来讲课,讲的是网络流 网络流--从入门到放弃:7-29dalao讲课笔记--https://hzoi-mafia.github.io/2017/07/29/27/   ...

随机推荐

  1. 指定UIView的某几个角为圆角

    如果需要将UIView的四个角全部设置为圆角,做法相当简单,只需要设置其layer的cornerRadius属性即可.而若要指定某几个角(小于4)为圆角,而别的角不变的时候,这种方法就不好用了.这种情 ...

  2. VC进程间通信之消息传递PostMessge()或SendMessage()

    1.  进程内消息: (1). 仅仅传消息码 (2). 传送消息串 发送端: void CTestDlg::OnBnClickedButtonSend() { CString* msg = new C ...

  3. anaconda2下面安装opencv2.4.13.4完成----解决默认安装的问题----Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support. If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg

    转载自:http://blog.csdn.net/qingyanyichen/article/details/73550924 本人下载编译安装了opencv2.4.9,oppencv2.4.10,o ...

  4. C# 杀掉后台进程

    var p = Process.GetProcessesByName("WINWORD"); if (p.Any()) { for (int i = 0; i < p.Len ...

  5. 【puppeteer+Node.js】学习

    总结了一下有关puppeteer的学习的网站,以后还会继续更新 puppeteer 介绍 Puppeteer是一个通过DevTools Protocol控制headless chromium的高级no ...

  6. PowerBuilder -- 其他

    判断某键是否被按下 KeyDown ( keycode ) 继承问题 如果是 uf_1是函数呢   你在父类UO_1的uf_1里面 写了代码,只要在子类UO_2的uf_1写了代码,默认是覆盖(over ...

  7. CString 成员函数用法大全(转)

    CString( );例:CString csStr; CString( const CString& stringSrc );例:CString csStr("ABCDEF中文12 ...

  8. memcached 搭建

     linux 下memcached 的搭建 memcached 下载地址:http://www.danga.com/memcached/dist/ libevent 下载地址:http://libev ...

  9. 【BZOJ3451】Tyvj1953 Normal 点分治+FFT+期望

    [BZOJ3451]Tyvj1953 Normal Description 某天WJMZBMR学习了一个神奇的算法:树的点分治!这个算法的核心是这样的:消耗时间=0Solve(树 a) 消耗时间 += ...

  10. Eclipse项目中引用第三方jar包时将项目打包成jar文件的两种方式

    转载自:http://www.cnblogs.com/lanxuezaipiao/p/3291641.html 方案一:用Eclipse自带的Export功能 步骤1:准备主清单文件 “MANIFES ...