cf B. Two Heaps
http://codeforces.com/contest/353/problem/B
题意:要把2*n个两位数分成两部分,使得第一部分上的数和第二部分上的两位数组成四位数。求怎么分能使构成的不同的四位数个数最多
如果2*n个数都是不同的,怎么分都一样的组成n*n个。如果有相同的,将它们按数量排序,均分到两个集合中就可以。
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std; int n;
int num[];
int a[],b[];
struct node
{
int x;
int id;
int flag;
int num;
bool operator <(const node &a)const
{
return (num<a.num)||(num==a.num&&x<a.x);
}
}p[]; bool cmp(node a,node b)
{
return a.id<b.id;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
int cnt=;
memset(num,,sizeof(num));
for(int i=; i<=*n; i++)
{
int m;
scanf("%d",&m);
p[cnt].id=i;
p[cnt++].x=m;
num[m]++;
}
for(int i=; i<cnt; i++)
{
p[i].num=num[p[i].x];
}
sort(p,p+cnt);
int t1=,t2=;
for(int i=; i<cnt; i+=)
{
p[i].flag=;
if(!a[p[i].x])
{
a[p[i].x]++;
t1++;
}
p[i+].flag=;
if(!b[p[i+].x])
{
b[p[i+].x]++;
t2++;
}
}
printf("%d\n",t1*t2);
sort(p,p+cnt,cmp);
for(int i=; i<cnt; i++)
{
if(i==)
{
if(p[i].flag==)
printf("");
else
printf("");
}
else
{
if(p[i].flag==)
printf("");
else printf("");
}
}printf("\n");
}
return ;
}
cf B. Two Heaps的更多相关文章
- CF 253B Two Heaps
#include<stdio.h> #include<algorithm> #include<map> using namespace std; struct No ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
随机推荐
- logstash multiline
filter { multiline { pattern => "^\s+%{TIMESTAMP_ISO8601}" negate=>true what=>&qu ...
- 瑞柏匡丞_免费app开发是否可行
随着移动互联时代的到来,手机APP软件开发已成为一大商机.当众人纷纷涌入这一领域“淘金”时,有人则做起了“卖水”的生意.无需编程知识和开发成本,只需要输入简单的文字指令,三分钟的时间就可以生成一个AP ...
- Android样式的编写格式
<?xml version="1.0" encoding="utf-8"?> <resources> <style name=&q ...
- [LeetCode] 35. Search Insert Position 解决思路
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- java基础知识(一)
基本特征:封装性,继承性,多态性 一些新特征: 静态导入:import static 包名 可变参数的函数:add(int -x) 增强版for循环: for(int x:xs) 自动拆箱: 基本类型 ...
- jQuery的基本语法
index.html代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- mongoose--------ORM数据操作框架
数据关系映射:ORM O:object R:relation M:mapping 把对数据库的操作都封装到对象中,操作了对象,就相当于操作了数据库. 安装: npm install mongoose ...
- (转)iOS keychain API及其封装
一. Keychain API KeyChain中item的结构为: 1.增加keychain Item OSStatus SecItemAdd (CFDictionaryRef attributes ...
- 高性能WEB开发(11) - flush让页面分块,逐步呈现
高性能WEB开发(11) - flush让页面分块,逐步呈现 在处理比較耗时的请求的时候,我们总希望先让用户先看到部分内容,让用户知道系统正在进行处理,而不是无响应.一般大家在处理这样的情况,都使用a ...
- mvc之验证IEnumerable<T> 类型
假设我们有这么一种需求,我们要同时添加年级和年级下面的多个班级,我们一般会像下面这种做法. Action中我们这样接收: [HttpPost] public ActionResult CreateGr ...