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. 【论文笔记】Zero-shot Recognition via semantic embeddings and knowledege graphs

    Zero-shot Recognition via semantic embeddings and knowledege graphs   2018-03-31  15:38:39  [Abstrac ...

  2. Component 初识组件

    component组件是Vue学习的重点.重点.重点,重要的事情说三遍.所以你必须学好Vue component.其实组件就是制作自定义的标签,这些标签在HTML中是没有的.比如:<diy> ...

  3. 51Nod—1174 区间中最大的数 线段树模版

    在大佬们题解的帮助下算是看懂了线段树吧...在这mark下防一手转头就忘. #include<iostream> #include<stdio.h> using namespa ...

  4. Python有趣现象(不定时更新)

    1.list中extend方法有趣现象 1.1 List+=Str 与 List.extend(Str) list1 = [11,2,45] str1 = 'Michael' list1.extend ...

  5. JqGrid 自定义子表格 及 自定义Json 格式数据不展示

    项目第一次使用JqGrid ,发现功能强大,但由于对他不熟悉,也没有少走弯路,记录一下. 1.引用 <link href="~/Scripts/JqGrid/jqgrid/css/ui ...

  6. Spring-MVC依赖

    <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api& ...

  7. 关于在mac安装安卓的模拟器的一些些那点事情~~~

    ook~~自己捣鼓了三天终于安装成功了~妹的~踩了太多的坑~整个人就不好了~ 为了节省大家的时间~所以今天我就将我安装的过程整体思路教给大家!有了思路安装起来就很好了!!!但是 注意的是,也许你会出现 ...

  8. Android Studio 使用USB真机调试教程

    允许安装未知来源的软件 允许USB调试 设置启动方式 选择USB device 然后运行 会自动安装软件启动! 参考: https://blog.csdn.net/fubo1990/article/d ...

  9. hadoop中 bin/hadoop fs -ls ls: `.': No such file or directory问题

    2.x版本上的使用bin/hadoop fs -ls  /就有用 应该使用绝对路径就不会有问题 mkdir也是一样的 原因:-ls默认目录是在hdfs文件系统的/user/用户名(用户名就命令行@符号 ...

  10. arcgis 属性表字段值计算

    1 如果你用VBSCRIPT的代码,那就在对应的选择项目处选择下,如果是PYTHON代码,就在另外一点点一下.如果弄混了,显然代码会报错. 2 VBSCRIPT里面的函数非常少,但是你可以去利用这些函 ...