为什么要今天写呢?

明天全力研究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. SQL Server常用系统表

    1.查询当前数据库中的用户表 select *from sysobjects where xtype='U'; 2.获取SQL Server允许同时用户连接的最大数 SELECT @@MAX_CONN ...

  2. python scrapy爬虫框架

    http://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.html scrapy 提取html的标签内容 from scrapy.selec ...

  3. Java&amp;Xml教程(十)XML作为属性文件使用

    我们一般会将Java应用的配置參数保存在属性文件里.Java应用的属性文件能够是一个正常的基于key-value对,以properties为扩展名的文件.也能够是XML文件. 在本案例中.將会向大家介 ...

  4. doT.js具体使用介绍

    官网: http://olado.github.iodoT.js具体使用介绍 用法: {{= }} for interpolation {{ }} for evaluation {{~ }} for ...

  5. struts2 Eclipse 中集成strust2开发框架实例

    下面通过建立一个小的实例具体来说明Eclipse 集成struts2,以下实例采用的为 struts2 版本为 struts2 2.2.3.1 为应用. 1. 下载struts2的开发包 第一步: 在 ...

  6. IOS开发之----异常处理

    本文转载至 http://blog.csdn.net/chenyong05314/article/details/7906593 转载自:http://blog.sina.com.cn/s/blog_ ...

  7. sql中decode()重要函数使用

    decode()函数简介: 主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1,翻译值1,值2,翻译值2,.. ...

  8. 如何解决安装好的google浏览器打不开网页的问题?

    1.Google浏览器右上角,三个点,点击一下, 2.点击设置 3.在"搜索引擎"这一栏,选择'管理搜索引擎',右边的倒三角,进入选择界面 4.在其他搜索引擎中选择"百度 ...

  9. 图床QAQ

  10. python列表(list)常用方法

    #!/usr/bin/env python # -*- coding:utf-8 -*- a = [1, 2, 3, 4, 5] # 索引 print(a[0], a[1], a[2], a[3], ...