Separate lib, new problems and script for web
This commit is contained in:
@@ -0,0 +1 @@
|
||||
https://usaco.org/index.php?page=viewproblem2&cpid=1276
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
// ----- TYPES -----
|
||||
typedef long long ll;
|
||||
typedef pair<int,int> pii;
|
||||
typedef vector<int> vi;
|
||||
|
||||
// ----- FILE IO -----
|
||||
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||
#define NL '\n'
|
||||
#define CM ", "
|
||||
|
||||
// ----- FOR LOOPS -----
|
||||
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||
|
||||
// ----- WEZ -----
|
||||
#define takeI(n) int n; cin >> n
|
||||
#define takeII(n,m) int n, m; cin >> n >> m
|
||||
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||
#define takeL(n) ll n; cin >> n
|
||||
#define takeS(s) string s; cin >> s
|
||||
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||
#define whileZ takeI(T); while(T--)
|
||||
//
|
||||
// ----- MAX MIN -----
|
||||
#define REMAX(a,b) (a)=max((a),(b))
|
||||
#define REMIN(a,b) (a)=min((a),(b))
|
||||
|
||||
// ----- PAIRS -----
|
||||
#define fi first
|
||||
#define se second
|
||||
|
||||
// ----- OUTPUT -----
|
||||
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||
|
||||
// ----- DEBUG -----
|
||||
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||
#define printV(a) printA(a,0,SZ(a)-1)
|
||||
|
||||
// ----- STL DS
|
||||
#define ALL(c) (c).begin(),(c).end()
|
||||
#define SZ(c) ((int)(c).size())
|
||||
#define SORT(c) sort(ALL(c))
|
||||
#define RSORT(c) sort(ALL(c), greater<>())
|
||||
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||
#define pb push_back
|
||||
|
||||
int main() {
|
||||
FASTIO;
|
||||
|
||||
takeII(n,m);
|
||||
vector<tuple<int,int,int>> cows(n);
|
||||
F(i,0,n) {
|
||||
int s,t,c;
|
||||
cin >> s >> t >> c;
|
||||
cows[i] = {s,t,c};
|
||||
}
|
||||
|
||||
vector<tuple<int,int,int,int>> conditioners(m);
|
||||
F(i,0,m) {
|
||||
int a,b,p,m;
|
||||
cin >> a >> b >> p >> m;
|
||||
conditioners[i] = {a,b,p,m};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
https://usaco.org/index.php?page=viewproblem2&cpid=668
|
||||
@@ -0,0 +1,110 @@
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
// ----- TYPES -----
|
||||
typedef long long ll;
|
||||
typedef pair<int,int> pii;
|
||||
typedef vector<int> vi;
|
||||
|
||||
// ----- FILE IO -----
|
||||
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||
#define NL '\n'
|
||||
#define CM ", "
|
||||
|
||||
// ----- FOR LOOPS -----
|
||||
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||
|
||||
// ----- WEZ -----
|
||||
#define takeI(n) int n; cin >> n
|
||||
#define takeII(n,m) int n, m; cin >> n >> m
|
||||
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||
#define takeL(n) ll n; cin >> n
|
||||
#define takeS(s) string s; cin >> s
|
||||
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||
#define whileZ takeI(T); while(T--)
|
||||
//
|
||||
// ----- MAX MIN -----
|
||||
#define REMAX(a,b) (a)=max((a),(b))
|
||||
#define REMIN(a,b) (a)=min((a),(b))
|
||||
|
||||
// ----- PAIRS -----
|
||||
#define fi first
|
||||
#define se second
|
||||
|
||||
// ----- OUTPUT -----
|
||||
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||
|
||||
// ----- DEBUG -----
|
||||
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||
#define printV(a) printA(a,0,SZ(a)-1)
|
||||
|
||||
// ----- STL DS
|
||||
#define ALL(c) (c).begin(),(c).end()
|
||||
#define SZ(c) ((int)(c).size())
|
||||
#define SORT(c) sort(ALL(c))
|
||||
#define RSORT(c) sort(ALL(c), greater<>())
|
||||
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||
#define pb push_back
|
||||
|
||||
int squared_dist(int x, int y, int xx, int yy) {
|
||||
int xDiff = abs(xx-x);
|
||||
int yDiff = abs(yy-y);
|
||||
return (xDiff * xDiff + yDiff * yDiff);
|
||||
}
|
||||
|
||||
vector<bool> seen;
|
||||
int dfs(const vector<vector<int>>& edges, int node) {
|
||||
seen[node] = true;
|
||||
int res = 1;
|
||||
for (auto nbor : edges[node]) {
|
||||
if (!seen[nbor]) res += dfs(edges, nbor);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
STDIO("moocast");
|
||||
|
||||
takeI(n);
|
||||
vi x(n), y(n), p(n);
|
||||
F(i,0,n) {
|
||||
int z;
|
||||
cin >> x[i] >> y[i] >> z;
|
||||
p[i] = z*z;
|
||||
}
|
||||
|
||||
// Convert to graph
|
||||
vector<vector<int>> edges(n);
|
||||
F(i,0,n-1) {
|
||||
F(j,i+1, n) {
|
||||
int sq = squared_dist(x[i], y[i], x[j], y[j]);
|
||||
if (sq <= p[i] || sq <= p[j]) {
|
||||
edges[i].push_back(j);
|
||||
edges[j].push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
seen = vector<bool>(n, false);
|
||||
int ans = 0;
|
||||
F(i,0,n) {
|
||||
if (seen[i]) continue;
|
||||
REMAX(ans, dfs(edges,i));
|
||||
}
|
||||
cout << ans;
|
||||
|
||||
// Find size of largest connected components
|
||||
// Components connected if dist(X, Y) < p_x
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
4
|
||||
1 3 5
|
||||
5 4 3
|
||||
7 2 1
|
||||
6 1 1
|
||||
|
||||
@@ -1,53 +1,98 @@
|
||||
// #include "../../debugging.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
void preprocessPrices(vector<long long> &prices) {
|
||||
for (int i = 1; i < prices.size(); i++) {
|
||||
prices[i] = min(2 * prices[i - 1], prices[i]);
|
||||
}
|
||||
}
|
||||
// ----- TYPES -----
|
||||
typedef long long ll;
|
||||
typedef pair<int,int> pii;
|
||||
typedef vector<int> vi;
|
||||
|
||||
int cheapest(const vector<long long> &prices, long long query) {
|
||||
long long sum = 0;
|
||||
// ----- FILE IO -----
|
||||
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||
#define NL '\n'
|
||||
#define CM ", "
|
||||
|
||||
for (int j = 0; j < prices.size(); j++) {
|
||||
if (query % 2 == 1) {
|
||||
sum += prices[j];
|
||||
}
|
||||
query /= 2;
|
||||
}
|
||||
// ----- FOR LOOPS -----
|
||||
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||
|
||||
int over = 2;
|
||||
while (query > 0) {
|
||||
if (query % 2 == 1) {
|
||||
sum += over * prices.back();
|
||||
}
|
||||
over *= 2;
|
||||
query /= 2;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
// ----- WEZ -----
|
||||
#define takeI(n) int n; cin >> n
|
||||
#define takeII(n,m) int n, m; cin >> n >> m
|
||||
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||
#define takeL(n) ll n; cin >> n
|
||||
#define takeS(s) string s; cin >> s
|
||||
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||
#define whileZ takeI(T); while(T--)
|
||||
//
|
||||
// ----- MAX MIN -----
|
||||
#define REMAX(a,b) (a)=max((a),(b))
|
||||
#define REMIN(a,b) (a)=min((a),(b))
|
||||
|
||||
// ----- PAIRS -----
|
||||
#define fi first
|
||||
#define se second
|
||||
|
||||
// ----- OUTPUT -----
|
||||
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||
|
||||
// ----- DEBUG -----
|
||||
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||
#define printV(a) printA(a,0,SZ(a)-1)
|
||||
|
||||
// ----- STL DS
|
||||
#define ALL(c) (c).begin(),(c).end()
|
||||
#define SZ(c) ((int)(c).size())
|
||||
#define SORT(c) sort(ALL(c))
|
||||
#define RSORT(c) sort(ALL(c), greater<>())
|
||||
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||
#define pb push_back
|
||||
|
||||
int main() {
|
||||
int N, Q;
|
||||
cin >> N >> Q;
|
||||
STDIO("pails");
|
||||
takeII(n,q);
|
||||
|
||||
vector<long long> prices(N);
|
||||
for (int i = 0; i < N; i++) {
|
||||
cin >> prices[i];
|
||||
|
||||
vi a(n);
|
||||
for (auto &x : a) cin >> x;
|
||||
|
||||
vi querys(q);
|
||||
int mx = 0;
|
||||
for (auto &query : querys) {
|
||||
takeI(z);
|
||||
REMAX(mx,z);
|
||||
query = z;
|
||||
}
|
||||
|
||||
preprocessPrices(prices);
|
||||
|
||||
vector<long long> queries(Q);
|
||||
for (int i = 0; i < Q; i++) {
|
||||
cin >> queries[i];
|
||||
F(i,1,n) {
|
||||
a[i] = 2*a[i-1] < a[i] ? 2*a[i-1] : a[i];
|
||||
}
|
||||
F(i,n,log2(mx)) a.push_back(2*a[i-1]);
|
||||
|
||||
for (int i = 0; i < Q; i++) {
|
||||
cout << cheapest(prices, queries[i]) << '\n';
|
||||
while(q--) {
|
||||
int cost = INT_MAX;
|
||||
int running_cost = 0;
|
||||
|
||||
takeI(remaining);
|
||||
|
||||
while(remaining > 0) {
|
||||
int low = log2(remaining);
|
||||
int high = low + 1;
|
||||
REMIN(cost, running_cost + a[high]);
|
||||
remaining -= pow(2,low);
|
||||
running_cost += a[low];
|
||||
}
|
||||
REMIN(cost, running_cost);
|
||||
cout << cost << NL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
2 4
|
||||
10 15
|
||||
1
|
||||
2
|
||||
6
|
||||
7
|
||||
@@ -0,0 +1,13 @@
|
||||
4 10
|
||||
10 25 30 70
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
15
|
||||
101
|
||||
|
||||
Reference in New Issue
Block a user