Skip to content

Instantly share code, notes, and snippets.

@ngobach
Last active November 5, 2017 15:23
Show Gist options
  • Save ngobach/98f0cf38238c85d5bb51cd99a5b2402f to your computer and use it in GitHub Desktop.
Save ngobach/98f0cf38238c85d5bb51cd99a5b2402f to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b_=(b);i<_b_;i++)
#define ROF(i,a,b) for (int i=(a),_b_=(b);i>_b_;i--)
#define IT(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) v.begin(), v.end()
#define MS(v) memset(v,0,sizeof(v))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}
const int N = 1005;
int n,m,a[N],b[N];
void solve() {
scanf("%d",&n);
FOR(i,0,n) {
scanf("%d",&a[i]);
}
scanf("%d",&m);
FOR(i,0,m) {
scanf("%d", &b[i]);
}
int t,u, mn = INT_MAX;
FOR(i,0,n) {
scanf("%d",&t);
FOR(j,0,t) {
scanf("%d",&u);
mn = min(mn, a[i]+b[u-1]);
}
}
scanf("%d",&t);
printf("%d", max(0, t/mn-1));
}
int main(){
#ifdef NGOBACH
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); solve();
}
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b_=(b);i<_b_;i++)
#define ROF(i,a,b) for (int i=(a),_b_=(b);i>_b_;i--)
#define IT(i,v) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) v.begin(), v.end()
#define MS(v) memset(v,0,sizeof(v))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}
typedef pair<int,int> II;
struct Edge { int u, v, w; };
bool operator< (const Edge &a, const Edge &b) { return a.w < b.w; }
const int N = 1e5+5;
int n,m,al;
int par[N];
vector<int> E[N];
Edge M[N<<1];
bool vis[N];
LL fuck;
int getPar(int i) {
if (par[i] == i) return i;
return (par[i] = getPar(par[i]));
}
LL path(int s, int t) {
MS(vis);
int P = getPar(s);
queue<II> q;
q.push(II(s, 0));
while (!q.empty()) {
II nx = q.front(); q.pop();
if (vis[nx.first]) continue;
vis[nx.first] = true;
if (nx.first == t) {
return nx.second;
}
IT(it, E[nx.first]) {
Edge ed = M[*it];
if (ed.u != nx.first) swap(ed.u, ed.v);
if (getPar(ed.v) == P && !vis[ed.v] && ed.w < fuck) {
q.push(II(ed.v, nx.second+1));
}
}
}
throw "Error?";
}
void solve() {
cin >> n >> m >> al;
FOR(i,1,n+1) par[i] = i;
FOR(i,0,m) {
cin >> M[i].u >> M[i].v >> M[i].w;
}
sort(M,M+m);
FOR(i,0,m) {
E[M[i].u] += i;
E[M[i].v] += i;
}
FOR(i,0,m) {
Edge nx = M[i];
int p = getPar(nx.u), q = getPar(nx.v);
if (p == q) {
fuck = nx.w;
cout << (path(nx.u, nx.v)+1)*al + LL(nx.w)*nx.w;
return;
}
par[q] = p;
}
cout << "Poor girl";
}
int main(){
#ifdef NGOBACH
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b_=(b);i<_b_;i++)
#define ROF(i,a,b) for (int i=(a),_b_=(b);i>_b_;i--)
#define IT(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) v.begin(), v.end()
#define MS(v) memset(v,0,sizeof(v))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}
typedef pair<int,int> II;
const int N = 1e6+8;
int T,a,b,P10[8],c;
II P[N*10];
void init() {
c = 0;
FOR(n,1,N) {
int len = int(log10(n)), t = n;
FOR(i,0,len) {
t = t%10*P10[len]+t/10;
if (t==n)
break;
if (t<n&&int(log10(t)) == len)
P[c++] = II(t,n);
}
}
}
void solve() {
scanf("%d", &T);
P10[0] = 1;
FOR(i,1,8) {
P10[i] = P10[i-1]*10;
}
init();
while (T--) {
scanf("%d%d",&a,&b);
int ans = 0;
FOR(i,0,c) if (P[i].first >= a && P[i].second <= b) {
ans++;
}
printf("%d\n", ans);
}
}
int main(){
#ifdef NGOBACH
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); solve();
}
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b_=(b);i<_b_;i++)
#define ROF(i,a,b) for (int i=(a),_b_=(b);i>_b_;i--)
#define IT(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) v.begin(), v.end()
#define MS(v) memset(v,0,sizeof(v))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}
int T,w,h;
double calc(double W, double H) {
double a = 12;
double b = -(4*W+4*H);
double c = H*W;
double d = b*b-4*a*c;
if (d<0) {
return 0;
}
d = sqrt(d);
double h = (-b-d)/2/a;
if (h<0) return 0;
return 4*h*h*h-(2*W+2*H)*h*h+W*H*h;
}
void solve() {
scanf("%d",&T);
while (T--) {
scanf("%d%d", &w, &h);
printf("%.11f\n", calc(w,h));
}
}
int main(){
#ifdef NGOBACH
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); solve();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment