A

http://codeforces.com/contest/685/standings

题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的7进制的位数相同,b满足要求:0<=b<m,b的7进制的位数和m-1的7进制的位数相同,且a和b的7进制下的位上的数都不相同

思路:如果a b的位数和大于7显然会有重复,缩小范围以后,可以根据题意暴力枚举

 // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N=;
const int M = ;
const int MOD = 1e9+;
#define LL long long
double const pi = acos(-);
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int dn,dm;
int digitt(int x){
if(x==) return ;
int ans=;
while(x){
ans++;
x/=;
}
return ans;
} int fun(int x,int d){
int s=;
for(int i=;i<=d;i++){
if(s&(<<(x%)))
return -;
s|=(<<(x%));
x/=;
}
return s;
}
void work(int n,int m){
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int tem1=fun(i,dn),tem2=fun(j,dm);
if(tem1!=-&&tem2!=-&&(tem1&tem2)==){
ans++;
}
}
}
printf("%d\n",ans);
} int main(){
int n,m;
cin>>n>>m;
n--,m--;
dn=digitt(n);
dm=digitt(m);
if(dn+dm>)
cout<<<<endl;
else{
work(n,m);
}
return ;
}

B

题意:找树的重心(删除该节点以后,最大子树的节点数小于等于原树的一半)

思路:预处理每个节点的数目,记录每个点的前驱,从最大子树的重心往上找该当前节点的重心(当前节点的重心一定在最大子树的重心和它的连线上)。并且重心唯一

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <conio.h>
#define clc(a,b) memset(a,b,sizeof(a))
#include <bits/stdc++.h>
const int maxn = ;
const int inf=0x3f3f3f3f;
const double pi=acos(-);
typedef long long LL;
using namespace std;
//const LL MOD = 1e9+7;
void fre(){freopen("in.txt","r",stdin);}
const int N = ;
int s[N],mx[N];
int ma[N];
int f[N];
vector<int> e[N]; void dfs(int u){
s[u]=;
for(int i=;i<e[u].size();i++){
int v=e[u][i];
dfs(v);
s[u]+=s[v];
mx[u]=max(mx[u],s[v]);
}
} void dfs2(int u){
if(e[u].size()==){
ma[u]=u;
return;
}
int x=;
for(int i=;i<e[u].size();i++){
int v=e[u][i];
dfs2(v);
if(s[x]<s[v])
x=v;
}
int y=ma[x];
while(){
if(max(mx[y],s[u]-s[y])<=s[u]/){
ma[u]=y;
break;
}
if(y==u)
break;
y=f[y];
}
}
int main(){
int n,q;
cin>>n>>q;
for(int i=;i<=n+;i++)
e[i].clear();
for(int i=;i<=n;i++){
int x;
cin>>x;
f[i]=x;
e[x].push_back(i);
}
dfs();
dfs2();
while(q--){
int x;
cin>>x;
printf("%d\n",ma[x]);
}
return ; }

Codeforces Round #359 (Div. 1)的更多相关文章

  1. Codeforces Round #359 (Div. 2)C - Robbers' watch

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  3. Codeforces Round #359 (Div. 1) B. Kay and Snowflake dfs

    B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the pie ...

  4. Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力

    A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...

  5. Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题

    B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...

  6. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  7. Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索

    题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...

  8. Codeforces Round #359(div 2)

    A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...

  9. Codeforces Round #359 (Div. 2) D. Kay and Snowflake 树DP

    D. Kay and Snowflake     After the piece of a devilish mirror hit the Kay's eye, he is no longer int ...

随机推荐

  1. BZOJ 1710: [Usaco2007 Open]Cheappal 廉价回文

    Description 为了跟踪所有的牛,农夫JOHN在农场上装了一套自动系统. 他给了每一个头牛一个电子牌号 当牛走过这个系统时,牛的名字将被自动读入. 每一头牛的电子名字是一个长度为M (1 &l ...

  2. XML 创建

    using unityEngine; using System.Collections; using System.Linq; using System.Xml.Linq; using System; ...

  3. jquery 清空动态append添加元素,remove方法

    <html> <head> <script type="text/javascript" src="jquery-1.9.1.js" ...

  4. 深入浅出ShellExecute

    Q: 如何打开一个应用程序? ShellExecute(this->m_hWnd,"open","calc.exe",""," ...

  5. php采集远程文章简单类

    <?php /** * 采集类 * @author Milkcy * @copyright (C) 2012-2015 TCCMS.COM * @lastmodify 2012-07-10 14 ...

  6. HDU4647+贪心

    /* 贪心. 题意:给定一些点 一些边 点和边都有价值.现在A B 选点.求A-B的maxVal 思路:分割边.边的1/2分给两个端点. 如果这两个点被同一个人取,则ok:否则 做减法也行,对题意无影 ...

  7. 安卓从业者应该关注:Android 6.0的运行时权限

    Android 6.0,代号棉花糖,自发布伊始,其主要的特征运行时权限就很受关注.因为这一特征不仅改善了用户对于应用的使用体验,还使得应用开发者在实践开发中需要做出改变. 没有深入了解运行时权限的开发 ...

  8. 看文档要看仔细,英语要加强啊... cocos2d-x 的 API 和 对应版本的 cocos2d-js 的 API 没有完全对应

    /** * Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew ...

  9. ids & hdmi 原理

    http://www.taiwanwebinar.com/zh_TW/STATIC/SITE/dwc_hdmi_tx.pdf http://blog.csdn.net/g_salamander/art ...

  10. Struts-2.3.24.1官方例子-struts2-blank

    一.配置文件 1.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app id=&qu ...