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. SQL Server 常见数据类型介绍

    数据表是由多个列组成,创建表时必须明确每个列的数据类型,以下列举SQL Server常见数据类型的使用规则,方便查阅. 整数类型 int 存储范围是-2,147,483,648到2,147,483,6 ...

  2. 【ASP.NET】System.Web.Routing - Route Class

    Provides properties and methods for defining a route and for obtaining information about the route. ...

  3. c# 泛型的应用

    泛型静态类 & function作为参数 /// <summary> /// /// </summary> /// <typeparam name="O ...

  4. EF Core In-Memory Database Provider

    原文链接 This can be useful for testing, although the SQLite provider in in-memory mode may be a more ap ...

  5. 4、iptables扩展匹配及网络防火墙功能

    关于centos7   firewalld    http://www.ibm.com/developerworks/cn/linux/1507_caojh/index.html 如何保存及重载规则: ...

  6. 配置httpd支持https

    1.首先为192.168.108.159创建私有CA #cd /etc/pki/CA # (umask 077;openssl genrsa -out private/cakey.pem 2048) ...

  7. Echarts 设置地图大小

    项目中要添加地图,默认地图太小,折腾半天终于找到解决方案. series: [ { //name: '香港18区人口密度', type: 'map', mapType: 'jiangsu', // 自 ...

  8. React Native 组建之IOS和Android通用抽屉

    /** * Sample React Native App * https://github.com/facebook/react-native * @flow *npm:https://www.np ...

  9. 《Linux命令行与shell脚本编程大全》读书笔记

    第一章:初识Linux 1.linux可划分为四个部分:内核.GNU工具.图形化桌面环境.应用程序 2.内核主要负责:系统内存管理.软件程序管理.硬件设备管理.文件系统管理 3.内核的系统内存管理,有 ...

  10. 不可改变性imutable

    不可改变性是指一些对象在被创建之后不会因为某些方式改变,特别是针对任何可以改变哈希对象的哈希值的方式. 两者相联系是因为哈希键值一定是不可改变的,所以它们对应的哈希键值也不改变. 如果允许它们改变,那 ...