题目链接: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. JavaScript读二进制文件并用ajax传输二进制流

    综合网上多个教程,加上自己实践得出的方法,目前能够兼容谷歌.IE11.IE10. htmlbody里的内容,没什么特殊的. <div id="dConfirm"> &l ...

  2. MySql 首记

    1.连接数据: 格式是:  -P 端口号  -h  mysql主机名\ip -u root (用户)  -p 2.显示数据库: show databases; 3.选择数据库: use databas ...

  3. objective-c第六章课后练习5

    题5:用于翻转从终端输入数的各个位.然后修改这个程序,以便正确的输入负数. code: ,result_5 = ; NSLog(@"input num_5:"); scanf(&q ...

  4. 中国电信大亚DP607光猫破解,设置路由,wifi!关闭远程管理,改连接限制,SN码查询!

    破解方法:以下为破解方法(一):1.进入192.168.1.12.用户名输入anonymous,密码不用,登陆3.输入网址192.168.1.1/backupsettings.conf4.用记事本打开 ...

  5. 夺命雷公狗-----React---9--map数据的遍历

    比如我们要实现的是这种效果: 用这种方法来写,她只能写死在哪,没啥意思,所以我们定义一个数据,然后来测试下map方法对她遍历出来的数据 <!DOCTYPE html> <html l ...

  6. 用C++实现的SDK跨平台心得体会

    C/C++的跨平台特性相比于Java更加原生(Java是一次编译到处运行,而C/C ++则需要拿着源码重新编译一遍),实现一个C/C++跨平台程序一般有几点做法: 1.使用Qt 2.使用ANSI C/ ...

  7. Deferred解决JS同步问题

    测试脚本: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  8. [已解决] MyBatis 中bind用法

    JAVA: TC_ENTR_FLOW selectFlowForUpdate(String ENTR_ID); XML: <select id="selectFlowForUpdate ...

  9. easyui datagrid 行右键生成 动态获取(toolbar) 按钮

    var createGridRowContextMenu = function(e, rowIndex, rowData) { e.preventDefault(); var grid = $(thi ...

  10. Visual Studio的Web Performance Test提取规则详解(1)

    总结 Visual Studio的Web Performance Test是基于HTTP协议层的,它不依赖于浏览器,通过直接接收,发送HTTP包来和Web服务器交互.Web Performance T ...