Skip to content

Instantly share code, notes, and snippets.

@shahril96
Created May 12, 2018
Embed
What would you like to do?
eat.code.error.cry.repeat's (some) solutions for ACM ICPC Al-Khawarizmi 2018
while True:
N, M = map(int, input().split())
if N == 0 and M == 0:
break
table = [i for i in range(1, N+1)]
i = (M-1) % len(table)
while len(table) > 1:
del table[i]
i = i-1 # reset index
i = (i+M) % len(table)
print(table[0])
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int INF = (int)1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef set<int> si;
class UnionFind {
private:
vi p;
int numSets;
public:
UnionFind(int N) {
setSize.assign(N,1);
p.assign(N,0);
for (int i=0; i<N; i++) p[i]=i;
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i]));}
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) { p[findSet(i)] = findSet(j);}
};
struct Edge { int u,v,w; };
bool cmp(Edge &a, Edge &b) {
return a.w < b.w;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
// code kt sini
int T;
cin >> T;
for (int t=1; t<=T; t++) {
int V,E,u,v,w;
cin >> V >> E;
vector<Edge> edge, mst;
for (int i=0; i<E; i++) {
cin >> u >> v >> w;
Edge e = {u,v,w};
edge.push_back(e);
}
sort(edge.begin(), edge.end(), cmp);
UnionFind uf(V+20);
int total=0;
for (int i=0; i<E; i++) {
u = edge[i].u, v = edge[i].v, w = edge[i].w;
if(!uf.isSameSet(u,v)) {
uf.unionSet(u,v);
mst.push_back(edge[i]);
total += w;
}
}
cout << "Case #" << t << ": " << total << " meters" << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int INF = (int)1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef set<int> si;
int matA[30][30], matB[30][30];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
// code kt sini
int M, N, P, Q;
for (int q=1; ; q++) {
int matC[30][30];
cin >> M >> N >> P >> Q;
if (M+N+P+Q == 0) break;
for (int i=0; i<M; i++)
for (int j=0; j<Q; j++)
matC[i][j]=0;
for (int i=0; i<M; i++) {
for (int j=0; j<N; j++) {
cin >> matA[i][j];
}
}
for (int i=0; i<P; i++) {
for (int j=0; j<Q; j++) {
cin >> matB[i][j];
}
}
cout << "Case #" << q << ":" << endl;
if (N != P) {
cout << "undefined" << endl;
} else {
for (int i=0; i<M; i++) {
for (int j=0; j<Q; j++) {
for (int k=0; k<P; k++) {
matC[i][j] += matA[i][k] * matB[k][j];
}
}
}
for (int i=0; i<M; i++) {
cout << "| ";
for (int j=0; j<Q; j++) {
cout << matC[i][j] << ' ';
}
cout << "|" << endl;
}
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int INF = (int)1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef set<int> si;
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(0);
// code kt sini
for (int t=1; true; t++) {
int n;
cin >> n;
if (n == 0) break;
double A=0,B=0,C=0,D=0;
while(n--) {
double A_T,B_T,C_T,D_T;
cin >> A_T >> B_T >> C_T >> D_T;
A += A_T;
B += B_T;
C += C_T;
D += D_T;
}
double spice_price = (A+B+C)/85 * 8;
double modal = A/85*7.5 + B/85*24 + C/85*32 + 0.2*D + spice_price;
double untung = A*0.8 + B + C*1.2 + D*0.8;
printf("Case #%d: RM%.2lf\n", t, untung-modal);
}
return 0;
}
fib = [0 for i in range(1000)]
fib[0] = 1
fib[1] = 1
for i in range(2,1000):
fib[i] = fib[i-1]+fib[i-2]
while True:
n = int(input())
if n == -1: break
print("Hour {}: {} cow(s) affected".format(n, fib[n-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment