Created
October 1, 2015 00:33
-
-
Save tmt514/f31df8662cd37407a544 to your computer and use it in GitHub Desktop.
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
void solve() { | |
int a[4]={}; | |
for(int i=0;i<4;i++) | |
scanf("%d", &a[i]); | |
sort(a, a+4); | |
if(a[0]+a[1]+a[2] > a[3]) puts("Possible"); | |
else puts("Impossible"); | |
} | |
int main(void) { | |
int T; | |
scanf("%d", &T); | |
while(T--) solve(); | |
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
int main(void) { | |
int x; | |
vector<int> a; | |
while(scanf("%d", &x)!=EOF) a.push_back(x); | |
int n = SZ(a), ans=0; | |
for(int i=0;i<n;i++) | |
for(int j=i+1;j<n;j++) | |
if(a[i] > a[j]) ++ans; | |
printf("%d\n", ans); | |
sort(a.begin(), a.end()); | |
for(int i=0;i<n;i++) | |
printf("%d%c", a[i], i==n-1?'\n':' '); | |
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <set> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
int n; | |
int nxt(int v) { | |
int ret = 0; | |
while(v) { ret += v%10*(v%10); v/=10; } | |
return ret; | |
} | |
void solve() { | |
set<int> s; | |
int cnt = 0; | |
while(n!=1 && s.find(n) == s.end()) { | |
s.insert(n); | |
n = nxt(n); | |
++cnt; | |
} | |
if(n==1) printf("happy %d\n", cnt); | |
else printf("unhappy %d\n", cnt); | |
} | |
int main(void) { | |
while(scanf("%d", &n)!=EOF) solve(); | |
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <sstream> | |
#include <cassert> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
vector<string> a; | |
void solve(); | |
void readmatrix(int m, int A[105][105], int &wA, int &dA) { | |
int pos[105]={}, t=0; | |
for(int i=0;i<SZ(a[0]);i++) if(a[0][i]=='|') pos[t++] = i; | |
int L = pos[m*2], R = pos[m*2+1]; | |
int n = SZ(a); | |
wA = 0; | |
for(int i=0;i<n;i++) if(a[i][L] == '|') ++wA; | |
for(int i=0;i<wA;i++) { | |
int offset = 0; | |
dA = 0; | |
for(int j=L+1;j<R;j+=offset) { | |
if(sscanf(a[i].c_str() + j, "%d%n", &A[i][dA], &offset) < 1) break; | |
++dA; | |
} | |
} | |
} | |
int dA, dB, wA, wB; | |
int A[105][105], B[105][105], C[105][105]; | |
void input() { | |
string x; | |
while(getline(cin, x) && !cin.fail()) { | |
a.push_back(x); | |
} | |
int m = 0; | |
for(int i=0;i<SZ(a[0]);i++) | |
if(a[0][i] == '|') ++m; | |
m/=2; | |
for(int i=0;i<m;i++) { | |
if(i==0) { | |
readmatrix(i, A, wA, dA); | |
} else { | |
readmatrix(i, B, wB, dB); | |
solve(); | |
} | |
} | |
} | |
void solve() { | |
int wC = wA; | |
int dC = dB; | |
for (int i = 0; i < wC; i++) | |
for (int j = 0; j < dC; j++) { | |
assert(dA == wB); | |
C[i][j] = 0; | |
for (int k = 0; k < wB; k++) { | |
C[i][j] += A[i][k] * B[k][j]; | |
} | |
} | |
wA = wC; | |
dA = dC; | |
for(int i=0;i<wA;i++) | |
for(int j=0;j<dA;j++) | |
A[i][j] = C[i][j]; | |
} | |
void output() { | |
int ali[105]={}; | |
for(int j=0;j<dA;j++) { | |
int &width = ali[j]; | |
for(int i=0;i<wA;i++) { | |
char s[1000]; | |
sprintf(s, "%d", A[i][j]); | |
width = max(width, (int)strlen(s)); | |
} | |
} | |
for (int i = 0; i < wA; i++) { | |
printf("|"); | |
for(int j = 0; j < dA; j++) | |
printf("%*d", ali[j]+1, A[i][j]); | |
printf(" |\n"); | |
} | |
} | |
int main(void) { | |
input(); | |
output(); | |
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
char s[10005]; | |
void go(LL &ans, int &nc, int v) { | |
for(int i=1;i<=v;i++) { | |
ans = ans * (++nc) / i; | |
} | |
} | |
void solve() { | |
int n = strlen(s); | |
int a[128]={}; | |
for(int i=0;i<n;i++) a[(int)s[i]]++; | |
int odd = 0; | |
long long ans = 1; | |
int nc = 0; | |
for(int i='a';i<='z';i++) { | |
if(a[i]%2) ++odd; | |
go(ans, nc, a[i]/2); | |
} | |
int min_remove = max(odd-1, 0); | |
printf("%d,%lld\n", min_remove, ans); | |
} | |
int main(void) { | |
while(scanf("%s", s)!=EOF) solve(); | |
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
struct Data { | |
int id, score, duration; | |
}; | |
bool cmp(Data &a, Data &b) { | |
if( a.score * b.duration != a.duration * b.score) | |
return a.score * b.duration > a.duration * b.score; | |
else if (a.duration != b.duration) | |
return a.duration < b.duration; | |
else | |
return a.id < b.id; | |
} | |
int main(void) { | |
int T, ID, score, duration; | |
vector<Data> v; | |
scanf("%d", &T); | |
while(scanf("%d,%d,%d", &ID, &score, &duration)!=EOF) { | |
v.push_back((Data){ID, score, duration}); | |
} | |
vector<int> ans; | |
int special = -1; | |
sort(v.begin(), v.end(), cmp); | |
int total = 0; | |
for(auto &x : v) { | |
if(T >= x.duration) { | |
T -= x.duration; | |
total += x.score; | |
ans.push_back(x.id); | |
} else if(T > 0) { | |
total += x.score * T / x.duration; | |
ans.push_back(x.id); | |
special = x.id; | |
T = 0; | |
break; | |
} | |
} | |
sort(ans.begin(), ans.end()); | |
printf("%d\n", total); | |
for(int i=0;i<SZ(ans);i++) { | |
printf("%d", ans[i]); | |
if(ans[i] == special) printf("*"); | |
if(i<SZ(ans)-1) printf(","); | |
} | |
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 <algorithm> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#define SZ(x) ((int)(x).size()) | |
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) | |
using namespace std; | |
typedef long long LL; | |
int tr(char w) { | |
if(w>='0' && w<='9') return w-'0'; | |
return w-'a'+10; | |
} | |
char trb(int w) { | |
if(w<10) return '0'+w; | |
else return w-10+'a'; | |
} | |
int main(void) { | |
char s[1005]; | |
int p, q; | |
while(scanf("%[^,\n],%d,%d ", s, &p, &q)!=EOF) { | |
long long r=0; | |
int bad = 0; | |
if(p < 2 || p > 36) bad = 1; | |
if(q < 2 || q > 36) bad = 1; | |
for(int i=0;s[i];i++) { | |
int v = tr(s[i]); | |
if(v<0 || v >= p) { | |
bad = 1; | |
} | |
r=r*p+tr(s[i]); | |
} | |
if(bad) { puts("Invalid Input"); continue; } | |
string w=""; | |
while(r) { | |
w+= trb(r%q); | |
r/=q; | |
} | |
if(w=="") w = "0"; | |
reverse(w.begin(), w.end()); | |
printf("%s\n", w.c_str()); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment