Created
November 24, 2013 11:13
-
-
Save sim642/7626055 to your computer and use it in GitHub Desktop.
EIO lahtine võistlus 2013
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
int main() | |
{ | |
ifstream fin("kangsis.txt"); | |
ofstream fout("kangval.txt"); | |
int L, N; | |
fin >> L >> N; | |
int a = 0, b = 0; | |
for (int i = 0; i < N; i++) | |
{ | |
int X, M; | |
fin >> X >> M; | |
a += M; | |
b += M * X; | |
} | |
double D = double(b) / a; | |
fout << D << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
int main() | |
{ | |
ifstream fin("kastsis.txt"); | |
ofstream fout("kastval.txt"); | |
int N; | |
fin >> N; | |
for (int i = 0; i < N; i++) | |
{ | |
unsigned int M; | |
fin >> M; | |
int set = 0; | |
for (int i = 0; i < 32; i++) | |
set += (M >> i) & 1; | |
unsigned int M2 = (M << 1) | (set & 1); | |
fout << M2 << endl; | |
} | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iomanip> | |
using namespace std; | |
int main() | |
{ | |
ifstream fin("kastsis.txt"); | |
ofstream fout("kastval.txt"); | |
int N; | |
fin >> N; | |
for (int i = 0; i < N; i++) | |
{ | |
string M; | |
fin >> M; | |
int sum = 0; | |
for (string::iterator it = M.begin(); it != M.end(); ++it) | |
sum += *it - '0'; | |
fout << M << "*" << oct << sum << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
int main() | |
{ | |
ifstream fin("kastsis.txt"); | |
ofstream fout("kastval.txt"); | |
int N; | |
fin >> N; | |
for (int i = 0; i < N; i++) | |
{ | |
string M; | |
fin >> M; | |
int w[] = {3, 7, 9}; | |
int sum = 0; | |
for (int i = M.length() - 1; i >= 0; i--) | |
sum += (M[i] - '0') * w[(M.length() - 1 - i) % 3]; | |
fout << M << (sum % 10) << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
using namespace std; | |
#define bitRead(value, bit) (((value) >> (bit)) & 0x01) | |
#define bitSet(value, bit) ((value) |= (1UL << (bit))) | |
#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) | |
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) | |
#define bit(b) (1UL << (b)) | |
int N; | |
vector<int> Ms; | |
vector<int> Ps; | |
vector<double> ps; | |
double avgRep(unsigned &avail, int d = 0); | |
double bestRep(unsigned &avail, int d = 0); | |
vector<double> avgLook, bestLook; | |
int main() | |
{ | |
ifstream fin("sallsis.txt"); | |
ofstream fout("sallval.txt"); | |
fin >> N; | |
for (int i = 0; i < N; i++) | |
{ | |
int M, P; | |
fin >> M >> P; | |
Ms.push_back(M); | |
Ps.push_back(P); | |
} | |
int sum = accumulate(Ps.begin(), Ps.end(), 0); | |
for (int i = 0; i < N; i++) | |
ps.push_back(double(Ps[i]) / sum); | |
avgLook.assign(bit(N), -1); | |
bestLook.assign(bit(N), -1); | |
unsigned avail = bit(N) - 1; | |
double ret = bestRep(avail); | |
fout << ret << endl; | |
return 0; | |
} | |
double bestRep(unsigned &avail, int d) | |
{ | |
if (bestLook[avail] >= 0) | |
return bestLook[avail]; | |
if (avail == 0) | |
{ | |
return 0; | |
} | |
double best = -1; | |
for (int i = 0; i < N; i++) | |
{ | |
if (bitRead(avail, i)) | |
{ | |
double rep = Ms[i]; | |
bitClear(avail, i); | |
rep += avgRep(avail, d + 1); | |
bitSet(avail, i); | |
if (rep > best) | |
best = rep; | |
} | |
} | |
bestLook[avail] = best; | |
return best; | |
} | |
double avgRep(unsigned &avail, int d) | |
{ | |
if (avgLook[avail] >= 0) | |
return avgLook[avail]; | |
if (avail == 0) | |
{ | |
return 0; | |
} | |
double avg = 0; | |
for (int i = 0; i < N; i++) | |
{ | |
bool is = bitRead(avail, i); | |
bitClear(avail, i); | |
double rep = bestRep(avail, d + 1); | |
bitWrite(avail, i, is); | |
avg += ps[i] * rep; | |
} | |
avgLook[avail] = avg; | |
return avg; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <vector> | |
#include <algorithm> | |
#include <utility> | |
using namespace std; | |
const string mast = "shdc"; | |
const string korgus = "AKQJT98765432"; | |
int main() | |
{ | |
ifstream fin("sortsis.txt"); | |
ofstream fout("sortval.txt"); | |
int N; | |
string S; | |
fin >> N >> S; | |
vector< pair<int, int> > cards; | |
for (int i = 0; i < N; i++) | |
{ | |
cards.push_back(make_pair(mast.find(S[2*i+1]), korgus.find(S[2*i]))); | |
} | |
sort(cards.begin(), cards.end()); | |
for (vector< pair<int, int> >::iterator it = cards.begin(); it != cards.end(); ++it) | |
fout << korgus[it->second] << mast[it->first]; | |
fout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment