钠 GZY整理贪心
CF140C New Year Snowmen
#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
#define rep(i , x, y) for(int i = x;i <= y;++ i)
#define sep(i , x, y) for(int i = x;i >= y;-- i)
#define PII pair<int,int>
#define mk make_pair
#define fi first
#define se second
const int maxN = 1e5 + 7;
inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
}
int cnt[maxN];
int a[maxN];
priority_queue<PII> q;
struct Ans {
int x,y,z;
}b[maxN];
int n;
void Read() {
n = gi();
rep(i , 1, n) a[i] = gi();
return;
}
void Pre() {
sort(a + 1,a + n + 1);
rep(i , 1, n) {
int p = lower_bound(a + 1,a + n + 1,a[i]) - a;
cnt[p] ++;
}
for(int i = 1;i <= n;++ i) {
if(cnt[i]) q.push(mk(cnt[i] , i));
}
}
void Solve() {
int k = 0;
while(q.size() >= 3) {
int x = q.top().se;q.pop();
int y = q.top().se;q.pop();
int z = q.top().se;q.pop();
b[++ k] = (Ans) {a[x] , a[y], a[z]};
if(b[k].z > b[k].y) swap(b[k].z , b[k].y);
if(b[k].y > b[k].x) swap(b[k].x , b[k].y);
if(b[k].z > b[k].y) swap(b[k].z , b[k].y);
cnt[x] --;if(cnt[x]) q.push(mk(cnt[x] , x));
cnt[y] --;if(cnt[y]) q.push(mk(cnt[y] , y));
cnt[z] --;if(cnt[z]) q.push(mk(cnt[z] , z));
}
printf("%d\n",k);
rep(i , 1, k) {
printf("%d %d %d\n",b[i].x,b[i].y,b[i].z);
}
}
int main() {
Read();
Pre();
Solve();
return 0;
}
CF161B Discounts
#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
#define rep(i , x, y) for(int i = x;i <= y;++ i)
#define sep(i , x, y) for(int i = x;i >= y;-- i)
#define PII pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define dbug(x) cout << "DEbug: " << x << '\n';
inline int gi() {
int x = 0 ,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
}
int n, k;
const int maxN = 1e3 + 7;
struct Node {
int id, c;
}a[maxN];
int t[maxN];
bool cmp(Node a, Node b) {
return a.c > b.c;
}
bool vis[maxN];
int ans[maxN];
void Solve() {
double ans1 = 0;
int n = gi(), k = gi();
for(int i = 1;i <= n;++ i) {
a[i].id = i;
a[i].c = gi();
ans1 += a[i].c;
t[i] = gi();
}
sort(a + 1, a + n + 1,cmp);
int num = 0;
for(int i = 1;i <= n;++ i) {
if(num < k - 1 && t[a[i].id] == 1) {
vis[i] = true;
ans[++ num] = a[i].id;
ans1 -= 1.0 * a[i].c / 2;
}
}
bool flag = false;
int minn = 0x7fffffff;
for(int i = 1;i <= n;++ i) {
if(!vis[i]) {
if(t[a[i].id]== 1) {
flag = true;
minn = min(minn ,a[i].c);
}
}
}
int tot = num;
for(int i = 1;i <= n;++ i) {
if(!vis[i]) {
if(tot == k - 1) break;
tot ++;
ans[tot] = a[i].id;
vis[i] = true;
}
}
if(flag) ans1 -= 1.0 * minn / 2;
cout << ans1 << '\n';
for(int i = 1;i < k;++ i) {
printf("1 %d\n",ans[i]);
}
int cnt = 0;
for(int i = 1;i <= n;++ i) {
if(!vis[i]) cnt ++;
}
printf("%d ",cnt);
for(int i = 1;i <= n;++ i) {
if(!vis[i]) {
printf("%d ",a[i].id);
}
}
}
int main() {
Solve();
return 0;
}
P1842 奶牛玩杂技
#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
#define rep(i , x, y) for(int i = x;i <= y;++ i)
#define sep(i , x, y) for(int i = x;i >= y;-- i)
#define int long long
const int inf = 0x7fffffff;
inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
return x * f;
}
const int maxN = 100000 + 7;
struct Node {
int w, s;
}a[maxN];
bool cmp(Node a , Node b) {return a.s + a.w > b.s + b.w;}
signed main() {
int n = gi();
rep(i , 1, n) {
a[i].w = gi();
a[i].s = gi();
}
sort(a + 1 , a + n + 1, cmp);
int ans = -inf;
int sum = 0;
sep(i , n, 1) {
ans = max(ans , sum - a[i].s);
sum += a[i].w;
}
printf("%lld",ans);
return 0;
}
钠 GZY整理贪心的更多相关文章
- nyoj 1216——整理图书 CF 229D—— Towers——————【dp+贪心】
整理图书 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 小明是图书鹳狸猿,他有很多很多的书堆在了一起摆在了架子上,每摞书是横着放的,而且每摞书是订好的 是一个整体, ...
- 贪心整理&一本通1431:钓鱼题解
题目传送 (其实有一个更正经的题解) 看了许久,发现这题貌似就是一个动态规划啊,但毕竟是贪心题库里的题,还是想想用贪心解吧. 经过(借鉴大佬思路)十分复杂的思考后,终于理解出了这题的贪心思路.该题的难 ...
- CodeForces - 721D 贪心+优先队列(整理一下优先队列排序情况)
题意: 给你一个长度为n的数组,你可以对其中某个元素加上x或者减去x,这种操作你最多只能使用k次,让你输出操作后的数组,且保证这个数组所有元素的乘积尽可能小 题解: 在这之前我们要知道a*b>a ...
- [Java面经]干货整理, Java面试题(覆盖Java基础,Java高级,JavaEE,数据库,设计模式等)
如若转载请注明出处: http://www.cnblogs.com/wang-meng/p/5898837.html 谢谢.上一篇发了一个找工作的面经, 找工作不宜, 希望这一篇的内容能够帮助到大 ...
- BZOJ 题目整理
bzoj 500题纪念 总结一发题目吧,挑几道题整理一下,(方便拖板子) 1039:每条线段与前一条线段之间的长度的比例和夹角不会因平移.旋转.放缩而改变,所以将每条轨迹改为比例和夹角的序列,复制一份 ...
- 背包dp整理
01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...
- Android面试题整理【转载】
面试宝典(5) http://www.apkbus.com/android-115989-1-1.html 面试的几个回答技巧 http://blog.sina.com.cn/s/blog_ad ...
- 【贪心+一点小思路】Zoj - 3829 Known Notation
借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可 ...
- HDU--3466(0-1背包+贪心/后效性)
题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有 价格 P 价值 V 还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...
随机推荐
- 引入 ServletContextListener @Autowired null 解决办法
public class ScheduleController implements ServletContextListener { @Autowired private ScheduleServi ...
- 一. jmeter
1.性能测试概述 1.1 主要方向是测试系统在一定负荷压力下,系统的响应时间,吞吐量,稳定性,系统的可扩展性等性能指标. 结合应用的架构和实现细节找出问题,并最终确认问题得到解决的过程. 目的: 1. ...
- linux安装php nginx mysql
linux装软件方式: systemctl status firewalld.service 查看防火墙systemctl stop firewalld.service systemctl disab ...
- Vue搭建脚手架1
Vue2.0搭建Vue脚手架(vue-cli) 此文章参考了网上一些前人的技术分享,自己拿过来总结一下.此文章是基于webpack构建的vue项目,并实现简单的单页面应用.其中利用到的相关技术会简单加 ...
- 从一道题看js的拆箱操作
前段时间看到一道题,如下:([][[]]+[])[+![]]+([]+{})[!+[]+![]]问最终打印结果,然后简单了解一下js的装箱,拆箱操作. 基本 装箱操作: 就是将基本类型(String, ...
- XenServer三类快照
三种类型的 VM 快照: 1.常规快照:仅创建磁盘快照,可以在所有 VM 类型(包括 Linux VM)上执行.还原快照会重启虚拟机 2.静态快照:生成虚拟机磁盘快照,生成快照前使 VM 静止.仅限于 ...
- 你遇到过哪些原因造成MySQL异步复制延迟?
master上多为并发事务,salve上则多为单线程回放(MySQL 5.7起,支持真正的并行回放,有所缓解) 异步复制,本来就是有一定延迟的(否则也不叫做异步了,介意的话可以改成半同步复制) sla ...
- main process exited, code=exited, status=203/EXEC
问题描述: Oct :: c_3. systemd[]: Started etcd. Oct :: c_3. systemd[]: Starting etcd... Oct :: c_3. syste ...
- Kali 安装tightvncserver
一.软件说明 a) tightvncserver是一个轻量级,只能建立桌面,不能查看TTY7/TTY1正在显示的桌面,但x11 vnc可以,相比x11vnc 安全传输差一些.反之,x11 vnc:安全 ...
- maven nexus 私服搭建 Linux版
准备工作 已安装jdk 已安装maven 下载Nexus Repository OSS:https://www.sonatype.com/download-oss-sonatype 如果无法下载成功, ...