태터데스크
관리자
태터데스크
메시지
저장하였습니다.
Talsu.net
Home
Tag
MediaLog
LocationLog
Guestbook
Admin
Write
search
Total |
143,496
Today |
11
Yesterday |
39
Study/Programming Challenges
2009/10/08 22:55
Programming Challenges - 호주식 투표법(Australian Voting)
문제 <- 클릭
아.. 이건 또 뭐가 문제지...? 체스 문제 처럼 나중에 다시보면 또 눈에 보이겠지.
시간 낭비는 하지말자.. 바쁘다!
#include
#include
#include
#include
typedef std::vector
Numbers; class AustralianVoting { std::vector
candidates; std::vector
persons; std::vector
votes; std::vector
eliminated; bool checkMoreVotes() { int max = 0; std::vector
::iterator it; for (it = votes.begin(); it != votes.end(); ++it) { if (max < *it) max = *it; // std::cout << *it << std::endl; } if (max > (int) persons.size() / 2) { // std::cout << "max > 50% : No more...." << std::endl; return false; } else if (votesAreSame()) { // std::cout << "Alive are Same : No more...." << std::endl; return false; } // std::cout << "More.." << std::endl; return true; } bool votesAreSame() { bool flag = true; int pre; int index = 0; std::vector
::iterator it; for (it = votes.begin(); it != votes.end(); ++it) { if (!eliminatedHas(index)) { if (flag) { pre = *it; flag = false; } else { if (pre != *it) return false; } } ++index; } return true; } int getBest() { int max = 0; int index = 0; std::vector
::iterator it; for (it = votes.begin(); it != votes.end(); ++it) { if (!eliminatedHas(index)) { if (max < *it) max = *it; } ++index; } return max; } int getWorst() { bool flag = true; int min = 1000; int index = 0; std::vector
::iterator it; for (it = votes.begin(); it != votes.end(); ++it) { if (!eliminatedHas(index)) { if (flag) { min = *it; flag = false; } else { if (min > *it) min = *it; } } ++index; } return min; } bool eliminatedHas(int val) { std::vector
::iterator it; for (it = eliminated.begin(); it != eliminated.end(); ++it) { if (*it == val) return true; } return false; } void voteR(std::vector
& vec, int depth) { if (depth > (int) candidates.size() - 1) return; // std::cout << "depth = " << depth << std::endl; int sizeI = vec.size(); int sizeJ = votes.size(); for (int i = 0; i < sizeI; ++i) { if (!eliminatedHas(vec[i][depth])) votes[vec[i][depth]] = votes[vec[i][depth]] + 1; } int worst = getWorst(); if (checkMoreVotes()) { std::vector
store; for (int j = 0; j < sizeJ; ++j) { if (!eliminatedHas(j)) { if (votes[j] == worst) { eliminated.push_back(j); // std::cout << j << " : eliminated(" <
::iterator it; for (it = votes.begin(); it != votes.end(); ++it) { if (!eliminatedHas(index)) { if (*it == getBest()) std::cout << candidates[index] << std::endl; } ++index; } } void reset() { candidates.clear(); persons.clear(); votes.clear(); eliminated.clear(); } void printNumbers() { int sizeI = persons.size(); int sizeJ = candidates.size(); for (int i = 0; i < sizeI; ++i) { for (int j = 0; j < sizeJ; ++j) { std::cout << persons[i][j] << " "; } std::cout << std::endl; } } void pushNumbers(Numbers& numbers) { persons.push_back(numbers); } void pushCandidates(std::string& name) { candidates.push_back(name); votes.push_back(0); } }; int main() { AustralianVoting av; std::string buffer; int numberOfCase; int numberOfCandidates; std::cin >> numberOfCase; std::getline(std::cin, buffer); for (int i = 0; i < numberOfCase; ++i) { if (i != 0) std::cout << std::endl; std::cin >> numberOfCandidates; // std::cout<<"numberOf Candidates : "<
> num) { nums.push_back(num - 1); } // std::cout<<"nums size : "<
크리에이티브 커먼즈 라이선스
이 저작물은
크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이선스
에 따라 이용하실 수 있습니다.
'
Study
>
Programming Challenges
' 카테고리의 다른 글
Programming Challenges - 포커 패 (Poker Hands)
(0)
2009/10/12
Programming Challenges - 유쾌한 점퍼(Jolly Jumpers)
(0)
2009/10/11
Programming Challenges - 호주식 투표법(Australian Voting)
(0)
2009/10/08
Programming Challenges - 체크 확인 (Check the Check)
(1)
2009/10/05
Programming Challenges - 인터프리터(Interpreter)
(2)
2009/10/04
Programming Challenges - 그래픽 편집기 (Graphical Editor)
(2)
2009/10/02
Posted by
탈수
TAG
Algorithm
,
Australian Voting
,
Programming Challenges
,
voting
,
알고리즘
,
투표
,
호주식 투표법
Trackback
0
Comment
0
TRACKBACK
http://talsu.net/trackback/122
«이전
1
...
8
9
10
11
12
13
14
15
16
...
98
다음»
RSS FEED
탈수
내 인생 내꺼 니 인생 니꺼!
카테고리
전체보기
(98)
Powershell
(0)
My Work
(30)
APP
(1)
JAVA Programming
(1)
FPGA / CPLD
(3)
C++ (TCPL)
(6)
AVR
(4)
Computer Hardware
(2)
Network
(4)
전자계산기 구조
(6)
....ing
(1)
Linux
(2)
Study
(14)
Programming Challe..
(12)
...
(0)
자료실
(4)
Utils
(4)
Documents
(0)
여행
(9)
Talsu's EuroTrip
(9)
Photos
(10)
Special Photo
(7)
나의 일상
(3)
I ♡ Drama
(30)
..
(0)
공지사항
talsu.net 새롭게 시작
태그목록
직렬화
serialize
Build Server
svn
ubuntu
Windows Server 2008 R2
타니그마
우분투
Subversion
cruisecontrol
c++
Tanigma
PowerShell
decryption
soap
vc++
File decryption
File encryption
암호화
Linux
c#
Windows Server Core
파일 암호화
방화벽
Serialization
파일 복호화
XML
빌드서버
.NET
Windows Server
최근에 올라온 글
회사 컴퓨터의 오후...
(1)
빌드서버 구축 - 200...
.NET(C#) Serializat...
(1)
SSH를 이용한 파일...
Ubuntu 9.10 - the K...
최근에 달린 댓글
프로그래머는...
Yoon
03/04
[Serializable]...
애국동맹
2009
친구랑 같이 풀...
최익필
2009
[비밀댓글].
2009
왠지 연산자 오...
탈수
2009
최근에 받은 트랙백
문제 11, 동맹...
최익필의 이름..
2009
ACM 10033 (Uva...
알고리즘 트레..
2009
ACM 10267 (Uva...
알고리즘 트레..
2009
5분영어 - grin...
Jessica's House
2008
<히어로즈&g...
젊은 베르테르..
2008
글 보관함
2010/02
(1)
2009/12
(1)
2009/11
(1)
2009/10
(16)
2009/04
(1)
달력
«
»
2010.07
일
월
화
수
목
금
토
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
링크
티스토리 홈
티스토리 가입하기