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. 在Oracle SQL Developer中创建新连接

    步骤: 1.如下图 2.点击“测试”,如果左下角的状态出现“成功”,说明OK

  2. PAT-乙级-1038. 统计同成绩学生(20)

    1038. 统计同成绩学生(20) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求读入N名学生的成绩,将 ...

  3. UNITY3D使用NGUI制作自适应UI的总结

    原地址:http://www.cnitblog.com/updraft/archive/2013/11/12/88801.html 制作自适应的几个方法1. 使用 UIROOT 里设置自定义高度的方法 ...

  4. HDU4612+Tarjan缩点+BFS求树的直径

    tarjan+缩点+树的直径题意:给出n个点和m条边的图,存在重边,问加一条边以后,剩下的桥的数量最少为多少.先tarjan缩点,再在这棵树上求直径.加的边即是连接这条直径的两端. /* tarjan ...

  5. linux动态库默认搜索路径设置的三种方法

    众所周知, Linux 动态库的默认搜索路径是 /lib 和 /usr/lib .动态库被创建后,一般都复制到这两个目录中.当程序执行时需要某动态库, 并且该动态库还未加载到内存中,则系统会自动到这两 ...

  6. 126. Word Ladder II

    题目: Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transfo ...

  7. Android 使用SDcard进行文件的读取

    平时我们需要在手机上面存储想音频,视频等等的大文件,以前学过使用File进行存储(使用File操作进行存储):由于考虑到手机本身的存储空间小,这时候我们需要把文件存储在SDcard中,今天自己也学习了 ...

  8. Oracle 列顺序测试

    列顺序测试 大家在做表设计的时候通常对表中列的排列顺序没有过多注意,但是其实越常用的列,它的位置越靠前,则查询速度越快. 因为每个block里面存储了row directory (每行数据在块中的位移 ...

  9. 工具----IcoFX

    IcoFX IcoFX 是一款免费的图标编辑工具,让您轻松创建 Windows XP 和 Windows Vista 图标. 在编辑区您可以轻松的预览.保存.更改您的图标.您可以将您喜欢的图像转换为图 ...

  10. Oracle安装时先决条件检查失败的解决方案

      Oracle安装时先决条件检查失败的解决方案 [java] 安装环境:Win7-64bit专业版,内存6G,硬盘空间足够 安装版本:Oracle Database 11g Release 2 (1 ...