A. Pens and Pencils 题目链接:https://codeforces.com/contest/1244/problem/A 题意: 给定五个数 a , b , c , d , k 求一对 x , y 使得 cx >= a , dy >= b , 且 x + y <= k 若无法找到满足条件的 x , y ,则输出 - 1 分析: 判断 a 是否能除尽 c , 如果能 , 则 x 最小可以为 c / a , 否则 x 最小可以为 a / c + 1 再判断 b 是否能除尽…
B. Invariance of Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/problem/B Description A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. W…
E. Ostap and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a conn…
C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line. Your task is to paint…
思路:x,y,z肯定不为负数xw+dy=p,直接枚举系数较小的y即可,y的范围:y<w,因为大于w的时候,不如去增加x,这样x+y的和还能保持尽可能小. /* x*w+y*d=p; x*w+(Kw+y)*d (x+d)*w+d; x+y+z=n; */ #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n,p,w,d;cin>>n>>p>…
给你一个数组,你最多可以进行k次操作,每次操作可以使一个数+1或者-1,问操作之后数组的极差最小可能是多少 利用map来模拟移动,可以观察到每次应该选择数量少的一组数让他们进行移动是最优的 int main(){ int n; ll k; cin >> n >> k; vector<int> a(n); map<int,int> ls; for(int i = 0 ; i < n ; i++) cin >> a[i],ls[a[i]]++;…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[1000007],b[1000007];int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; long long k; cin>>n>>k; if(k<1ll*n*(n+1)>>1){…
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted bla…
题目链接:http://codeforces.com/contest/734/problem/E E. Anton and Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Anton is growing a tree in his garden. In case you forgot, the tree is a…