题目链接: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的更多相关文章

  1. CodeForces - 158B.Taxi (贪心)

    CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...

  2. [Codeforces 1246B] Power Products (STL+分解质因数)

    [Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...

  3. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  4. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  5. 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 ...

  6. codeforces 724D(贪心)

    题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. CodeForces 651A Joysticks 贪心

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. Codeforces 626G Raffles(贪心+线段树)

    G. Raffles time limit per test:5 seconds memory limit per test:256 megabytes input:standard input ou ...

随机推荐

  1. 简要介绍Apache、php、mysql安装和工具介绍

    1 安装Apache 网站:www.Apache.org下载相应的Apache,目前下载了近期的:httpd-2.2.15-win32-x86-openssl-0.9.8msi 安装简要步骤如下图: ...

  2. Android--再探MVP模式

    1,上一篇我们已经了解了大致的MVP模式,下面再通过这个登录功能的例子 ,我们能过更加容易的掌握MVP模式,再来补充一些闲外话:MVP 是 MVC 的变种,其实是一种升级.要说 MVP 就要说说 MV ...

  3. http://www.miniui.com/demo/#src=datagrid/celledit.html

    http://www.miniui.com/demo/#src=datagrid/celledit.html   jQuery MiniUI Demo

  4. 配置本地光盘为yum源

    挂载cd-rom mount /dev/cdrom /mnt http://javaarm.com/faces/display.xhtml?tid=3520 关闭selinux vi /etc/sys ...

  5. windows平台(不包括ARM的CE)通用的压缩和解压缩

    通用是相对的,这里指的是xp和win7(其他版本我没测试过,不要用不要来找我) #define CMP_FRM COMPRESSION_FORMAT_LZNT1|COMPRESSION_ENGINE_ ...

  6. servlet定义

    . 运行在服务器上的java类

  7. 【转】appStore上传苹果应用程序软件发布流程

    转载地址:http://blog.sina.com.cn/s/blog_68661bd801019uzd.html 首先确定帐号是否能发布, https://developer.apple.com/a ...

  8. dotfiles管理

    刚刚知道dotfiles这个东西,百度也没发现什么太有价值的讲解,还都是英文,所以自己立志来好好屡屡清楚 1.dotfiles是什么?我自己的理解:linux下(mac下)有各种app,每个人会根据自 ...

  9. ADB指令

    对于ADB指令的应用,首先应该配置环境,将文件所在路径复制到高级系统设置里面的环境变量path,然后就可以在命令符上进行ADB的指示 例如adb kill-server是关掉活动 adb start- ...

  10. 简单的计算最值的MapReduce程序

    import java.io.IOException;import java.util.StringTokenizer;import java.util.*;import org.apache.had ...