题目链接: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. Leetcode: Partition Equal Subset Sum

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  2. windows系统调用 遍历进程的虚拟地址

    #include "iostream" #include "windows.h" #include "shlwapi.h" #include ...

  3. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(31)-MVC使用RDL报表

    系列目录 这次我们来演示MVC3怎么显示RDL报表,坑爹的微软把MVC升级到5都木有良好的支持报表,让MVC在某些领域趋于短板 我们只能通过一些方式来使用rdl报表. Razor视图不支持asp.ne ...

  4. Visual Studio常用插件

    Visual Assist X 番茄不用说了,C# C++编码必备 Image Insertion 可以在代码编辑器中插入图片注释,让代码像Word文档一样图文并茂. 但注意必须是PNG格式的图片,直 ...

  5. ASP.NET 管道事件与HttpModule, HttpHandler简单理解

    BeginRequest 指示请求处理开始 AuthenticateRequest 封装请求身份验证过程 AuthorizeRequest 封装检查是否能利用以前缓存的输出页面处理请求的过程 Reso ...

  6. SQL 是什么?

    一.简介   SQL,Structured Query Language,结构化查询语言.  

  7. mac os 添加用户到组 命令

    mac os 添加用户到组 命令 dscl localhost 进入组目录 cd /Local/Default/Groups 使用ls 你就可以看到所有的group,? /Local/Default/ ...

  8. 配置rt-thread开发环境(配置系统,生成系统镜像)

    配置rt-thread开发环境 ===========Python============= 1.Python的下载地址:http://www.python.org/ftp/python/ 链接中有各 ...

  9. DSO、CUBE区别(覆盖、合计)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  10. shell学习笔记1

    知识点1.修改输出的颜色 echo -e "\e[1;31m This is red text \e[0m" 其中,\e[1;31m 表示将输出显示为红色: \e[0m 标识将颜色 ...