http://codeforces.com/contest/1088/problem/A

暴力一波就好了。

//题解有O(1)做法是 (n-n%2,2)

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<deque>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<cstdlib>
#include<ctype.h>
#include<ctime>
#include<functional>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define debug puts("debug")
#define mid ((L+R)>>1)
#define lc (id<<1)
#define rc (id<<1|1)
const int maxn=;
const int maxm=;
const double PI=acos(-1.0);
const double eps=1e-;
const LL mod=1e9+;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL qpow(LL a,LL b,LL c){LL r=; for(;b;b>>=,a=a*a%c)if(b&)r=r*a%c;return r;}
template<class T>
void prt(T v){for(auto x:v)cout<<x<<' ';cout<<endl;}
struct Edge{int u,v,w,next;};
int main(){
int t,n,m,i,j,k,u,v;
int ans=-;
cin>>n;
for(i=;i<=n;++i){
for(j=;j<=n;++j){
if(i%j==&&i*j>n&&i/j<n){
cout<<i<<' '<<j<<endl;
return ;
}
}
}
cout<<ans<<endl;
return ;
}

http://codeforces.com/contest/1088/problem/B

排下序然后遍历一遍。容易发现被减数总等于前一个a[i]。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<deque>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<cstdlib>
#include<ctype.h>
#include<ctime>
#include<functional>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define debug puts("debug")
#define mid ((L+R)>>1)
#define lc (id<<1)
#define rc (id<<1|1)
const int maxn=;
const int maxm=;
const double PI=acos(-1.0);
const double eps=1e-;
const LL mod=1e9+;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL qpow(LL a,LL b,LL c){LL r=; for(;b;b>>=,a=a*a%c)if(b&)r=r*a%c;return r;}
template<class T>
void prt(T v){for(auto x:v)cout<<x<<' ';cout<<endl;}
struct Edge{int u,v,w,next;};
int a[maxn];
int main(){
int t,n,m,i,j,k,u,v;
cin>>n>>k;
for(i=;i<=n;++i)scanf("%d",a+i);
sort(a+,a++n);
int d=;
for(i=,j=;i<=n&&k;i++){
if(a[i]-d==)continue;
printf("%d\n",a[i]-d);
k--;
d=a[i];
}
while(k--)puts("");
return ;
}

http://codeforces.com/contest/1088/problem/C

构造,题目里的n+1就是提示了,从n-1开始倒着遍历,进行n次加法每次都让当前的数%n等于i,最后摸一次n就好。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<deque>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<cstdlib>
#include<ctype.h>
#include<ctime>
#include<functional>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define debug puts("debug")
#define mid ((L+R)>>1)
#define lc (id<<1)
#define rc (id<<1|1)
const int maxn=;
const int maxm=;
const double PI=acos(-1.0);
const double eps=1e-;
const LL mod=1e9+;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL qpow(LL a,LL b,LL c){LL r=; for(;b;b>>=,a=a*a%c)if(b&)r=r*a%c;return r;}
template<class T>
void prt(T v){for(auto x:v)cout<<x<<' ';cout<<endl;}
struct Edge{int u,v,w,next;};
LL a[maxn];
LL op[maxn],p1[maxn],p2[maxn],tot=;
int main(){
int t,n,m,i,j,k,u,v;
cin>>n;
for(i=;i<n;++i)scanf("%lld",a+i);
LL d=;
for(i=n-;i>=;--i){
if((a[i]+d)%n==i)continue;
else{
LL x=(a[i]+d)%n;
LL delta=(i-x+n)%n;
d+=delta;
op[tot]=;
p1[tot]=i+;
p2[tot]=delta;
tot++;
}
}
op[tot]=;
p1[tot]=p2[tot]=n;
tot++;
cout<<tot<<endl;
for(i=;i<tot;++i){
printf("%lld %lld %lld\n",op[i],p1[i],p2[i]);
}
return ;
}

http://codeforces.com/contest/1088/problem/E

给出一棵树,每个节点有权值a[i],找出k个互不重复覆盖的联通分量,使得SUM{a[i] | i in s} / k的值最大化,如果有多种方案选择k最大的方案。

假设最优解是{b1,b2...bk} 那么有公式  max{b}>=ave{b}  ,也就是说ave{b}的最大值就是max{b},问题转化为求最大权值和的连通分量,然后看有多少个等于ans的联通分量,就是k。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<deque>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<cstdlib>
#include<ctype.h>
#include<ctime>
#include<functional>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define debug puts("debug")
#define mid ((L+R)>>1)
#define lc (id<<1)
#define rc (id<<1|1)
const int maxn=;
const int maxm=;
const double PI=acos(-1.0);
const double eps=1e-;
const LL mod=1e9+;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL qpow(LL a,LL b,LL c){LL r=; for(;b;b>>=,a=a*a%c)if(b&)r=r*a%c;return r;}
template<class T>
void prt(T v){for(auto x:v)cout<<x<<' ';cout<<endl;}
struct Edge{int u,v,w,next;};
LL ans=-inf,f[maxn],a[maxn],k=;
vector<int>g[maxn];
void dfs(int u,int fa,bool o){
f[u]=a[u];
for(int v:g[u]){
if(v!=fa){
dfs(v,u,o);
if(f[v]>) f[u]+=f[v];
}
}
if(o)ans=max(ans,f[u]);
if(!o){
if(f[u]==ans){
k++;
f[u]=;
}
}
}
int main(){
int t,n=,m,i=,j,u,v;
scanf("%d",&n);
for(i=;i<=n;++i)scanf("%lld",a+i);
for(i=;i<n;++i){
scanf("%d%d",&u,&v);
g[u].pb(v),g[v].pb(u);
}
dfs(,,);
dfs(,,);
printf("%lld %lld\n",ans*k,k);
return ;
}

Codeforces Round #525 (Div. 2)-A/B/C/E的更多相关文章

  1. Codeforces Round #525 (Div. 2)

    Codeforces Round #525 (Div. 2) 哎,忍不住想吐槽一下,又要准备训练,又要做些无聊的事,弄得我都想退出了. 好好的训练不好么???? 只能做出两道水题,其实C题,感觉做出来 ...

  2. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  3. Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula

    F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...

  4. Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem

    E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...

  5. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  6. Codeforces Round #525 (Div. 2)后俩题

    E:https://codeforces.com/contest/1088/problem/E dp+贪心 题目大意:选择一个k并且选择k个连通块,要求sigma a[i]/k最大,k尽量大,对于给定 ...

  7. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)

    参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...

  8. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task

    传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...

  9. Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学

    题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可 ...

随机推荐

  1. [HDU 2520] 我是菜鸟,我怕谁(不一样的for循环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2520 //学学不一样的for循环 #include<iostream> #include& ...

  2. Vue内置的Component标签用于动态切换组件

    html <div id="app"> <component :is="cut"></component> <butt ...

  3. 正则匹配-URL-域名

    DNS规定,域名中的标号都由英文字母和数字组成,每一个标号不超过63个字符,也不区分大小写字母.标号中除连字符(-)外不能使用其他的标点符号.级别最低的域名写在最左边,而级别最高的域名写在最右边.由多 ...

  4. hihoCoder 1233 : Boxes(盒子)

    hihoCoder #1233 : Boxes(盒子) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 There is a strange ...

  5. StringBuilder的三种删除方法比较

    分别用一千万次循环来比较StringBuilder的三种删除方法所用时间 未避免偶然性,再循环一百次来比较总时间 --主类 public class StringBuilderRemove { pub ...

  6. 前端js实现 blob转base64位 和 base64位转blob

    //**dataURL to blob** function dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0]. ...

  7. 【Django】【三】模型

    [基本数据访问] 1. models.py写模型 2. 数据库迁移 guest> python manage.py makemigrations sign guest> python ma ...

  8. _pvp_killed_loot

    该表控制玩家被击杀时掉落物品,包括角色身上装备,背包物品,银行物品 comment 备注 entry 掉落的物品ID lootCount 掉落的物品数量 chance 掉落的几率,例如50,则50%几 ...

  9. 转csdn某位同学的 感谢bmfont

    UGUI 使用BMFont 首先要知道 Custom Font 的原理,不知道的同学可以先看这篇[Custom Font 原理](http://blog.csdn.net/liqiangeastsun ...

  10. Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland dfs

    D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...