题意 :
思路 :
#include
#include
#include
#define endl '\n'
#define _(a) cout << #a << ": " << (a) << " "
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2500 + 10;
int c, l;
PII cows[N];
map<int, int> ma;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> c >> l;
for (int i = 0; i < c; ++ i) cin >> cows[i].first >> cows[i].second;
sort(cows, cows + c);
for (int i = 0; i < l; ++ i) {
int spf, cnt;
cin >> spf >> cnt;
ma[spf] += cnt;
}
ma[0] = ma[1001] = c; // 就算值换成负数也可以ac
int cnt = 0;
for (int i = c - 1; i >= 0; -- i) {
auto pos = ma.upper_bound(cows[i].second);
-- pos;
if (pos->first >= cows[i].first && pos->first <= cows[i].second) {
cnt ++ ;
if ( -- pos->second == 0) {
ma.erase(pos);
}
}
}
cout << cnt;
}
题意 :
思路 :
#include
#include
#include
#define endl '\n'
#define _(a) cout << #a << ": " << (a) << " "
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 5e4 + 10;
int n;
pair<PII, int> cows[N];
priority_queue<PII, vector<PII>, greater<PII>> heap;
int id[N];
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++ i) {
cin >> cows[i].first.first >> cows[i].first.second;
cows[i].second = i;
}
sort(cows + 1, cows + 1 + n);
for (int i = 1; i <= n; ++ i) {
if (heap.empty() || heap.top().first >= cows[i].first.first) {
PII stall = {cows[i].first.second, heap.size() + 1};
id[cows[i].second] = heap.size() + 1;
heap.push(stall);
} else {
PII stall = heap.top(); heap.pop();
id[cows[i].second] = stall.second;
stall.first = cows[i].first.second;
heap.push(stall);
}
}
cout << heap.size() << endl;
for (int i = 1; i <= n; ++ i) cout << id[i] << endl;
}
题意 :
思路 :
#include
#include
#include
using namespace std;
typedef pair<double, double> pdd;
const int N = 1e3 + 10;
const double eps = 1e-6;
pdd seg[N];
bool cmp(pdd u, pdd v) {
if (u.second != v.second) return u.second < v.second;
return u.first < v.first;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
double last = -1e20;
int n, d, cnt = 0;
cin >> n >> d;
for (int i = 0; i < n; ++ i) {
int x, y;
cin >> x >> y;
if (y > d) {
cout << -1;
return 0;
}
double len = sqrt(d * d - y * y);
seg[i] = {x - len, x + len};
}
sort(seg, seg + n, cmp);
for (int i = 0; i < n; ++ i) {
if (seg[i].first > last + eps) {
cnt ++ ;
last = seg[i].second;
}
}
cout << cnt;
}
题意 :
思路 :
#include
#include
#include
using namespace std;
typedef pair<int, int> pii;
const int N = 1e3 + 10;
int n;
pii p[N];
bool cmp(pii a, pii b) {
return a.first * a.second < b.first * b.second;
}
vector<int> mul(vector<int> &a, int b) {
vector<int> c;
int t = 0;
for (int i = 0; i < a.size(); ++ i) {
t += a[i] * b;
c.push_back(t % 10);
t /= 10;
}
while (t) {
c.push_back(t % 10);
t /= 10;
}
return c;
}
vector<int> div(vector<int> &a, int b) {
vector<int> c;
int t = 0;
bool is_first = true;
for (int i = a.size() - 1; i >= 0; -- i) {
t = t * 10 + a[i];
int x = t / b;
if (x || !is_first) {
is_first = false;
c.push_back(x);
t %= b;
}
}
reverse(c.begin(), c.end());
return c;
}
vector<int> chkmx(vector<int> &a, vector<int> &b) {
if (a.size() > b.size()) return a;
if (a.size() < b.size()) return b;
if (vector<int>(a.rbegin(), a.rend()) > vector<int>(b.rbegin(), b.rend())) return a;
return b;
}
int main() {
cin >> n;
for (int i = 0; i <= n; ++ i) {
cin >> p[i].first >> p[i].second;
}
sort(p + 1, p + n + 1, cmp);
vector<int> product;
product.push_back(1);
vector<int> mx;
mx.push_back(0);
for (int i = 0; i <= n; ++ i) {
if (i) {
vector<int> tmp = div(product, p[i].second);
mx = chkmx(mx, tmp);
}
product = mul(product, p[i].first);
}
for (int i = mx.size() - 1; i >= 0; -- i)
cout << mx[i];
}
题意 :
思路 :
代码实现:
#include
using namespace std;
const int N = 1e3 + 10;
struct Node {
int v, s, p;
double avg;
}nodes[N];
int n, root;
int find() {
double mx = 0;
int p;
for (int i = 1; i <= n; ++ i) {
if (i != root && nodes[i].avg > mx) {
mx = nodes[i].avg;
p = i;
}
}
return p;
}
int main() {
cin >> n >> root;
int ans = 0;
for (int i = 1; i <= n; ++ i) {
cin >> nodes[i].v;
nodes[i].avg = nodes[i].v;
nodes[i].s = 1;
ans += nodes[i].v;
}
for (int i = 0; i < n - 1; ++ i) {
int a, b;
cin >> a >> b;
nodes[b].p = a;
}
for (int i = 0; i < n - 1; ++ i) {
int p = find();
int father = nodes[p].p;
ans += nodes[father].s * nodes[p].v;
nodes[p].avg = -1;
for (int j = 1; j <= n; ++ j) {
if (nodes[j].p == p) {
nodes[j].p = father;
}
}
nodes[father].v += nodes[p].v;
nodes[father].s += nodes[p].s;
nodes[father].avg = nodes[father].v * 1.0 / nodes[father].s;
}
cout << ans;
}