Hack With Inf Y
Hack With Inf Y
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
main() {
int D, W;
while (cin >> D >> W) {
vector<pair<int, pair<int, int> > > MD;
vector<pair<int, double> > MC;
for (int i = 0; i < D; i++) {
char ch;
int w, t, dt;
cin >> ch;
if (ch == 'D') {
cin >> w >> t >> dt;
MD.push_back(make_pair(w, make_pair(t, dt)));
} else {
cin >> t >> dt;
MC.push_back(make_pair(t, dt));
}
}
vector<double> vc(W+1, -1e15);
vc[0] = 0;
double cw = 0.0, cv = 0.0;
int cwi = 0;
sort(MC.begin(), MC.end());
while (cwi <= W && MC.size()) {
while (MC.size() >= 2 && MC[MC.size()-2].first == MC[MC.size()-1].first) {
MC[MC.size()-2].second = 1.0 / (1.0/MC[MC.size()-1].second +
1.0/MC[MC.size()-2].second);
MC.pop_back();
}
double curt = MC.back().first, curdt = MC.back().second;
double nw = (curdt == 0.0) ? W+1 : cw + 1.0 / curdt;
while (cwi <= W && cwi <= nw) {
vc[cwi] = cv + (cwi-cw)*(curt + curt-(cwi-cw)*curdt)/2;
cwi++;
}
cv += (nw-cw)*(curt + curt-(nw-cw)*curdt)/2;
cw = nw;
MC.back().first--;
}
The Rocky Mountain National Park is opening up for tourist traffic. The national park has several
sites worth seeing and streets that connect pairs of sites. The park officials have put together a set of
round tours in the park in which visitors can ride buses to view various sites. Each round tour starts at
some site (potentially different sites for different tours), visits some other sites without repeating any,
and then returns to where it started. At least 3 different sites are visited in each round tour. At least
one round tour is possible in the national park.
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > c;
main() {
int n, m;
while (cin >> n >> m) {
c = vector<vector<int> >(n+1);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
c[a].push_back(b);
c[b].push_back(a);
}
int ret = 0;
for (int a = 1; a <= n; a++)
for (int i = 0; i < c[a].size(); i++) if (c[a][i] > a) {
depth = vector<int>(n+1, -1);
cura = a; goal = curb = c[a][i]; eq = 1;
//cout << cura << ',' << curb << " -";
if (doit(a, -1, 0).second) ret = Gcd(ret, eq);
//cout << endl;
}
You are about to meet Peterson, a close friend, and former partner in crime. Peterson lost most of his
money betting on a coding contest, so now he needs another job. For this, he needs your help, even
though you have retired from a life of crime. There is a shipment of expensive consumer gadgets in a
nearby distribution center and Peterson going to steal as much of it as he can. Finding a way into the
building, Peterson must pass through incapacitating security guards, arrays of laser beams. However,
the heart of the distribution center has been equipped with a security system that Peterson cannot
disable. So only he needs your help.
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main() {
int X, Y;
while (cin >> Y >> X) {
VVI g(Y, vector<int>(X));
VI xh(X), yh(Y);
long long ret = 0;
for (int y = 0; y < Y; y++)
for (int x = 0; x < X; x++) {
cin >> g[y][x];
ret += max(0, g[y][x] - 1);
xh[x] = max(xh[x], g[y][x]);
yh[y] = max(yh[y], g[y][x]);
}
set<int> seen;
for (int x = 0; x < X; x++) if (xh[x] > 1) {
ret -= xh[x]-1;
if (seen.count(xh[x])) continue;
seen.insert(xh[x]);
VVI mat;
for (int x2 = 0; x2 < X; x2++) if (xh[x2] == xh[x]) {
mat.push_back(vector<int>());
for (int y2 = 0, yi = 0; y2 < Y; y2++) if (yh[y2] == xh[x]) {
if (g[y2][x2]) mat.back().push_back(yi);
yi++;
}
}
VI v = BipartiteMatch(mat);
for (int i = 0; i < v.size(); i++) if (v[i] != -1) ret += xh[x]-1;
}
for (int y = 0; y < Y; y++) ret -= max(0, yh[y]-1);