CodeForces #100 C 贪心+STL
题目链接:CodeForces #100 C
题意:现在给出n个snowball的半径,3个半径严格递增或递减的snowball,可以组成1个snowmen。问最多能组成多少个snowmen。并且按照半径递减的顺序输出每个snowmen的组成。
思路:嗯...每次都从前三个个数最多的snowball里选择,最后组成的snowmen最多...
...可以用优先队列写..但是感觉set+map写的太优雅了...map当然不等于数组了...哼。
#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std; typedef pair<int, int> pair_;
map<int, int> mp;
set<pair_> st;
vector<int> ans; int main() {
//freopen("in.cpp", "r", stdin);
int n;
while(~scanf("%d", &n)) {
mp.clear();
st.clear();
ans.clear();
int temp;
for (int i=0; i<n; ++i) {
scanf("%d", &temp);
mp[temp]++;
}
map<int, int>::iterator mpit;
for (mpit = mp.begin(); mpit != mp.end(); ++mpit) {
//st.insert(pair_((*mpit).second, (*mpit).first));
st.insert(pair_(mpit->second, mpit->first));
}
while(st.size() >= 3) {
pair_ now[3];
for (int i=0; i<3; ++i) {
now[i] = *--st.end();
st.erase(--st.end());
ans.push_back(now[i].second);
}
for (int i=0; i<3; ++i) {
if (--now[i].first) st.insert(now[i]);
}
sort(ans.rbegin(),ans.rbegin()+3);
}
printf("%d\n", ans.size()/3);
for (int i=0; i<ans.size(); i+=3) {
printf("%d %d %d\n", ans[i], ans[i+1], ans[i+2]);
}
}
return 0;
}
CodeForces #100 C 贪心+STL的更多相关文章
- CodeForces - 158B.Taxi (贪心)
CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...
- [Codeforces 1246B] Power Products (STL+分解质因数)
[Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...
- Codeforces Round #595 (Div. 3)D1D2 贪心 STL
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- CodeForces - 620C Pearls in a Row 贪心 STL
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- CodeForces 651A Joysticks 贪心
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces 626G Raffles(贪心+线段树)
G. Raffles time limit per test:5 seconds memory limit per test:256 megabytes input:standard input ou ...
随机推荐
- windows系统调用 遍历进程的虚拟地址
#include "iostream" #include "windows.h" #include "shlwapi.h" #include ...
- windows系统调用 利用事件对象实现进程通信
#include "iostream" #include "windows.h" #include "cstring" using name ...
- FIFO深度
async fifo的full和empty的判断: 1)binary进制,MSB相同时,LSB也相同,empty: MSB不同时,LSB相同,full 2)gray code,MSB相同时,LSB也相 ...
- python的一些图像操作
from PIL import ImageGrabim = ImageGrab.grab()im.save("f:\\T.jpg",'jpeg') 直接用pyCharm安装PI ...
- CSS3 笔记一(Rounded Corners/Border Images/Backgrounds)
CSS3 Rounded Corners The border-radius property is a shorthand property for setting the four border- ...
- C# 的Brush 及相关颜色的操作 (并不是全转)
C# 的Brush 及相关颜色的操作 2013-12-13 14:08 4977人阅读 评论(0) 收藏 ...
- [转]为何需要调用“super viewDidLoad
转载地址:http://liwpk.blog.163.com/blog/static/36326170201165104413314/ - (void)didReceiveMemoryWarnin ...
- 【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
转载地址:http://blog.csdn.net/donglynn/article/details/17056099 错误 SQL 查询: DELETE FROM `zmax_lang` WHERE ...
- 浙江理工2015.12校赛-A
孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...
- NSDate获取当前时区的时间
[NSDate date]获取的是GMT时间,要想获得某个时区的时间,以下代码可以解决这个问题 NSDate *date = [NSDate date]; NSTimeZone *zone = [NS ...