您的位置:首页 > 其它

Codeforces Round #223 (Div. 2) 解题报告

2014-01-13 02:05 387 查看
这次只做出来两道水题,真是太糟糕了。先挖个坑,到时候再来填吧。

Problem A Sereja and Dima

思路:每次都会从两边去找一个最大的。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<unsigned int, unsigned int> puu;
typedef pair<int ,double> pid;
typedef pair<ll, int> pli;

const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int LEN = 100010;

int hash[LEN];

int main()
{
//    freopen("in.txt", "r", stdin);

int n;
while(scanf("%d", &n)!=EOF){
memset(hash, 0, sizeof hash);
int ans = 0;
for(int i=0; i<n; i++){
int temp;
scanf("%d", &temp);
hash[temp]++;
if(hash[temp]<3)ans++;
}
int maxt;
for(int i=5000; i>=0; i--){
if(hash[i]){
maxt = i;
break;
}
}
if(hash[maxt]>=2)ans--;
printf("%d\n", ans);
int f = 1;
for(int i=0; i<=5000; i++){
if(hash[i]){
if(f==1){printf("%d", i);f=0;}
else printf(" %d", i);
}
}
for(int i=5000; i>=0; i--){
if(hash[i]>=2){
if(i==maxt)continue;
if(f==1){printf("%d", i);f=0;}
else printf(" %d", i);
}
}
printf("\n");
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: