Codeforces Round #359 (Div. 1)
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索
题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...
- Codeforces Round #359(div 2)
A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...
- 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 ...
随机推荐
- 2817 Tangent的愤怒 - Wikioi
题目描述 Description 如果机房马上要关门了,或者你急着要和MM约会,请直接跳到第六个自然段. 第二段:本题改编自Usaco Training 4.4.2... 第三段:本题加大了数据强度. ...
- IE 浏览器下 button元素自动触发click?
为什么这么说呢?且看下面的情形: 当用户焦点在输入框中的时候,当用户按了“Enter”键之后,达到点击登录的效果:所以这里就监听了input的keydown事件,当keyCode是13的时候,就发送请 ...
- HIBERNATE一对一双向外键联合主键关联
HIBERNATE一对一双向外键联合主键关联: 一. 创建主键类:这个主键必须实现serializedable接口和重写其中的hashCode方法和equals方法:为主键类添加一个叫做@Embedd ...
- bzoj 1222: [HNOI2001]产品加工 dp
1222: [HNOI2001]产品加工 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 381 Solved: 218[Submit][Status ...
- The7th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Who is Older?
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3322 可以看样例猜题意的水题. #include<bits/stdc ...
- Monad学习
这是观看Cousera上的课程<Principles of Reactive Programming>中week1里的Monad一节所做的笔记. What is a Monad? What ...
- Python:使用threading模块实现多线程编程
转:http://blog.csdn.net/bravezhe/article/details/8585437 Python:使用threading模块实现多线程编程一[综述] Python这门解释性 ...
- 【leetcode】Container With Most Water(middle)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- QT插件开发方式(作者有RemOjbects文档翻译(48)篇)
创建一个QT的库项目,删除自动生成的.h和.cpp文件,添加一个接口定义.h文件和一个接口实现类(一个.h一个.cpp).代码如下: 1.接口文件源码 #ifndef PLUGININTERFACE_ ...
- 在vs2010中mfc,C++的一些小经验
1 如果你最近才从vc6.0到vs2010,在vs2010中mfc可能遇见一个小问题,如果你添加或改天了窗口中的控件,运行程序缺没有发现其中的变化,这时候需要在debug选项中rebuild all一 ...