Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

469ms。。。看来多组数据,1A

Posted by KatrineYang at 2016-09-24 13:12:59 on Problem 1355 and last updated at 2016-09-24 13:13:35
注意,一张选票上出现错误的位置,不仅仅是那个错误位置廢掉,而是整张票廢掉
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;

int scores[10] = {15,12     ,9     ,7    , 6     ,5       ,4      ,3     ,2     ,1};

int ws(int n){
	if(n<10)return 1;
	if(n<100)return 2;
	if(n<1000)return 3;
	if(n<10000)return 4;
	return 5;
}

struct teacher{
	int id;
	string name;
	string major;
	int votes;
	int score;
	int vote[10];
}t[102];

int numT, numS;

int ids[102];

void init(){
	for(int i = 0; i < 102; i++) ids[i] = -1;
	for(int i = 1; i <= numT; i++) {
		t[i].votes = 0;
		t[i].score = 0;
		for(int j = 0; j < 10; j++) t[i].vote[j] = 0;
	}
	for(int i = 1; i <= numT; i++){
		cin >> t[i].id >> t[i].name >> t[i].major;
		ids[t[i].id] = i;
	}
}


bool compare(const teacher& t1, const teacher& t2){
	return t1.score>t2.score ||
			(t1.score==t2.score && t1.votes>t2.votes) ||
			(t1.score==t2.score && t1.votes==t2.votes && t1.id<t2.id);
}

bool isFei(string s){
	bool used[102] = {0};
	for(int rank = 0; rank < 10; rank++){
		int tarId = (s[rank*2]-'0')*10+(s[rank*2+1]-'0');
		if(!tarId) continue;
		int wdbh = ids[tarId];
		if(!(~wdbh) || used[wdbh]) return 1;
		used[wdbh] = 1;
	}
	return 0;
}

void parse(string s){
	if(isFei(s)) return;
	for(int rank = 0; rank < 10; rank++){
		int tarId = (s[rank*2]-'0')*10 + (s[rank*2+1]-'0');
		if(!tarId) continue;
		int wdbh = ids[tarId];
		t[wdbh].votes++;
		t[wdbh].vote[rank]++;
		t[wdbh].score+=scores[rank];
	}
}

int main() {
	while(1){
		cin >> numT;
		if(!(~numT)) break;
		cin >> numS;
		init();
		string s;
		for(int i = 0; i < numS; i++) {
			cin >> s;
			parse(s);
		}
		sort(t+1, t+numT+1, compare);
		for(int i = 1; i <= 10; i++){
			printf("%d",i);
			printf("  ");
			if(i!=10)printf(" ");
			if(t[i].id<10)printf("0");
			printf("%d  ",t[i].id);
			int len = t[i].name.length();
			printf("%s", t[i].name.c_str());
			for(int j = 0; j < 15-len; j++) printf(" ");
			len = t[i].major.length();
			printf("%s", t[i].major.c_str());
			for(int j = 0; j < 37-len; j++) printf(" ");
			int w = ws(t[i].score);
			for(int j = 0; j < 6-w; j++)printf(" ");
			printf("%d",t[i].score);
			w = ws(t[i].votes);
			for(int j = 0; j < 6-w; j++) printf(" ");
			printf("%d",t[i].votes);
			for(int k = 0; k < 10; k++){
				w = ws(t[i].vote[k]);
				for(int j = 0; j < 6-w; j++) printf(" ");
				printf("%d",t[i].vote[k]);
			}
			printf("\n");
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator