Skip to content

Commit

Permalink
Dec 28, 2011
Browse files Browse the repository at this point in the history
  • Loading branch information
sitz committed Dec 28, 2011
1 parent 9e11702 commit 752f3b3
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 27 deletions.
83 changes: 83 additions & 0 deletions 10258.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
using namespace std;

struct Contestant {
bool solved[10];
int attempt[10];
int penalty, count;
};

map<int, Contestant> Contest;
vector< int > Index;

bool comp(int A, int B) {
if (Contest[A].count != Contest[B].count)
return (Contest[A].count > Contest[B].count);
if (Contest[A].penalty != Contest[B].penalty)
return (Contest[A].penalty < Contest[B].penalty);
return (A < B);
}

int main() {
int T;
stringstream ss;
string str;
getline(cin, str);
//cout << str << endl;
ss.clear();
ss << str;
ss >> T;
//cout << T << endl;
getline(cin, str);
//cout << str << endl;
while (T--) {
//cout << "T--\n";
Contest.clear();
Index.clear();
while (getline(cin, str)) {
//cout << str << endl;
if (str.empty()) break;
int A, B, C;
string D;
ss.clear();
ss << str;
ss >> A >> B >> C >> D;
//cout << A << " " << B << " " << C << " " << D << endl;

if (Contest.find(A) == Contest.end()) {
Contestant Con;
memset(Con.solved, false, sizeof Con.solved);
memset(Con.attempt, 0, sizeof Con.attempt);
Con.penalty = 0;
Con.count = 0;

Index.push_back(A);
Contest[A] = Con;
}
if (D == "C" || D == "I") {
if (Contest[A].solved[B]) continue;

if (D == "C") {
Contest[A].solved[B] = true;
Contest[A].penalty += (20 * Contest[A].attempt[B] + C);
Contest[A].count += 1;
}
else {
Contest[A].attempt[B] += 1;
}
}
}
sort(Index.begin(), Index.end(), comp);
for (int i = 0; i < Index.size(); i++) {
cout << Index[i] << " " << Contest[Index[i]].count << " " << Contest[Index[i]].penalty << endl;
}
if (T) cout << endl;
}
return 0;
}
92 changes: 92 additions & 0 deletions 11581.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <iostream>
#include <map>
using namespace std;

int board_value(int board[3][3]) {
int tmp = 0;

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
tmp = tmp * 10 + board[i][j];
}
}

return tmp;
}

void visit(int board[3][3], map<int,bool>& visited) {
visited[board_value(board)] = true;
}

void mutate(int board[3][3]) {
int tmp[3][3], sum;

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
sum = 0;

if (i > 0) {
sum += board[i-1][j];
}

if (j > 0) {
sum += board[i][j-1];
}

if (i < 2) {
sum += board[i+1][j];
}

if (j < 2) {
sum += board[i][j+1];
}

tmp[i][j] = sum % 2;
}
}

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
board[i][j] = tmp[i][j];
}
}
}

int main(void)
{
int t, index, tmp;
int board[3][3];
map<int,bool> visited;

cin >> t;

while (t--) {
index = -1;
visited.clear();

for (int i = 0; i < 3; i++) {
cin >> tmp;
for (int j = 2; j >= 0; j--) {
board[i][j] = tmp % 10;
tmp /= 10;
}
}

visit(board, visited);
index++;

while (true) {
mutate(board);

if (visited.find(board_value(board)) == visited.end()) {
visit(board, visited);
index++;
} else {
cout << index - 1 << endl;
break;
}
}
}

return 0;
}
48 changes: 21 additions & 27 deletions 146.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
for(;;){
string str;
cin>>str;
char ch[50];
for(int i=0;i<str.length();i++){
ch[i]=str[i];
}

if(str=="#")
break;

if(next_permutation(ch,ch+str.length())){
for(int i=0;i<str.length();i++){
cout<<ch[i];
}
cout<<endl;
}
else
cout<<"No Successor"<<endl;
}
return 0;
}
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
while (true) {
char ch[51];
scanf("%s", ch);
int L = strlen(ch);

if (strcmp(ch, "#") == 0)
return 0;

if (next_permutation(ch, ch + L))
printf("%s\n", ch);
else
printf("No Successor\n");
}
return 0;
}
32 changes: 32 additions & 0 deletions 855.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <algorithm>
#include <cstdio>
using namespace std;

int S[50005];
int A[50005];

int main() {
int T;
scanf("%d", &T);
while (T--) {
int F;
scanf("%*d%*d%d",&F);
for (int i = 0; i < F; i++) {
scanf("%d%d", &S[i], &A[i]);
}
sort(S, S + F);
sort(A, A + F);
int bestS = 0, bestA = 0;

if (F & 1) {
bestS = S[F / 2];
bestA = A[F / 2];
}
else {
bestS = S[(F - 1) / 2];
bestA = A[(F - 1) / 2];
}
printf("(Street: %d, Avenue: %d)\n", bestS, bestA);
}
return 0;
}

0 comments on commit 752f3b3

Please sign in to comment.