読者です 読者をやめる 読者になる 読者になる

日本情報オリンピック 第5回本選

Programming Algorithm JOI AOJ

JOI 2006 本選 問題・データ

1. Questionnaire

404 Not Found

#include <cstdio>
#include <map>
#include <set>
#include <vector>
using namespace std;
int main()
{
	int n, m;
	while(scanf("%d %d\n", &n, &m), n || m){
		map<int, int> ma;
		for(int i = 0; i < n; i++){
			for(int j = 0, x; j < m; j++){
				scanf("%d", &x);
				ma[j + 1] += x;
			}
		}
		map<int, set<int> > mi;
		for(map<int, int>::iterator it = ma.begin(); it != ma.end(); it++){
			mi[(*it).second].insert((*it).first);
		}
		vector<int> v;
		for(map<int, set<int> >::reverse_iterator rit = mi.rbegin(); rit != mi.rend(); rit++){
			for(set<int>::iterator it = (*rit).second.begin(); it != (*rit).second.end(); it++){
				v.push_back(*it);
			}
		}
		for(int i = 0; i < v.size() - 1; i++){
			printf("%d ", v[i]);
		}
		printf("%d\n", v[v.size() - 1]);
	}

	return 0;
}

2. String(2011/1/9)

404 Not Found

#include <iostream>
#include <string>
#include <sstream>
using namespace std;
inline string func(string s){
	ostringstream ss;
	char a = 0;
	int r = 1;
	for(string::iterator it = s.begin(); it != s.end(); it++){
		if(a != *it){
			if(a) ss<<r<<(char)a;
			a = *it;
			r = 1;
		}else{
			r++;
		}
	}
	if(a) ss<<r<<(char)a;
	return ss.str();
}

int main()
{
	int n;
	while(cin>>n, n){
		string s;
		cin>>s;
		for(int i = 0; i < n; i++){
			s = func(s);
		}
		cout<<s<<endl;
	}
	return 0;
}

3. Square(2011/1/9)

404 Not Found

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int> > *lists;

int listup(int n, vector<int> v){
	for(int i = 1; i <= n; i++){
		int f = 0;
		for(int j = 0; j < v.size(); j++){
			if(v[j] > i){
				f = 1;
				break;
			}
		}
		if(f) continue;
		vector<int> w = v;
		w.push_back(i);
		if(n - i > 0){
			listup(n - i, w);
		}else{
			lists->push_back(w);
		}
	}
}
int main()
{
	int n;
	while(scanf("%d\n", &n), n){
		vector<vector<int> > v;
		lists = &v;
		listup(n, vector<int>());
		for(int i = 0; i < v.size(); i++){
			reverse(v[i].begin(), v[i].end());
		}
		sort(v.begin(), v.end());
		for(int i = v.size() - 1; 0 <= i; i--){
			for(int j = 0; j < v[i].size(); j++){
				printf("%d%c", v[i][j], j != v[i].size() - 1 ? ' ' : '\n');
			}
		}
	}
	return 0;
}

4.

5.

are not solved.