vis

hdu 5354 树上点分治

丶灬走出姿态 提交于 2019-11-30 14:31:35
给出一颗n个结点的树,点上有权 求点对(x,y)的数量 其中 x!=y,x到y的路径上最大值与最小值的差<=D 按最小值排序,用最大值二分最小值比他小的所有点,容斥一下,最后答案*2即可 #include<bits/stdc++.h> #define ll long long #define rep(ii,a,b) for(int ii=a;ii<=b;++ii) #define per(ii,a,b) for(int ii=b;ii>=a;--ii) #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define fi first #define se second #define mp make_pair #define pii pair<int,int> using namespace std;//head const int maxn=1e5+10,maxm=2e6+10; const ll INF=0x3f3f3f3f,mod=1e9+7; int casn,n,m,k; int val[maxn]; namespace graph{ struct node{int to,next;}e[maxn<<1]; int head[maxn],nume,all,root,maxt,sz[maxn];

[CF1221G] Graph And Numbers

一笑奈何 提交于 2019-11-30 13:33:29
传送门: https://codeforces.com/contest/1221/problem/G sol: 感觉这个G题还挺好搞的…… 首先同时有$0$,$1$,$2$正面统计好像不大好统计 那就反过来 总方案数$2^n$ 然后要减去没有$0$的方案,没有$1$的方案,没有$2$的方案,加上没有$0,1$的方案,没有$0,2$的方案,没有$1,2$的方案,减去没有$1,2,3$的方案 我们分开讨论 显然 没有$0$的方案数和没有$2$的方案数是等价的 没有$0$的方案:考虑把填$0$设为$1$,其他设为$0$,$2^{40}$好像有点大 拆半找 然后对于一个确定的前半部分 后半部分不能选的方案就确定了,然后枚举后半部分取法 然后加上合法的前半边的计数就行了 没有$1$的方案:即一个联通块内同时填$0$或$1$,设联通块数为$c$,答案为$2^c$ 没有$0,1$的方案:即只有$2$的方案,这个时候可以发现,除了孤点,其他的点都填入$1$,只需要统计孤点的数量,设为$cnt$,答案为$2^{cnt}$ 没有$0,2$的方案:即只有$1$的方案,也就是说这时候是$0101$……这样交替填入。如果有奇环则不合法,如果没有奇环,答案为$2^c$,否则是$0$ 没有$1,2$的方案:只有$0$的方案,这时候和只有$2$的方案等价 没有$0,1,2$的方案 如果$m=0$ 答案为$2^n$

CF1209C Paint the Digits

一个人想着一个人 提交于 2019-11-30 12:32:17
CF1209C Paint the Digits 题意:给定T组数据,每组数据第一行输入数字串长度,第二行输入数字串,用数字1和2对数字串进行涂色,被1涂色的数字子串和被2涂色的数字子串拼接成新的数字串,要求新的数字串是非递减的。 题解:对原数字串进行排序,然后从后往前和从前往后各涂一次,若涂不完则输出“-”。 #include<iostream> #include<string.h> #include<string> #include<algorithm> using namespace std; string a,b; int vis[200005]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; cin>>a; b=a; memset(vis,0,sizeof(vis)); sort(b.begin(),b.end()); int pos1=n-1; for(int i=n-1;i>=0;i--) { if(b[pos1]==a[i]) { vis[i]=2; pos1--; } } pos1=pos1+1; int pos2=0; for(int i=0;i<n;i++) { if(vis[i]==0&&a[i]==b[pos2]) { vis[i]=1; pos2++; } } if(pos1!=pos2)

Codeforces Round #588 (Div. 2)(思维,暴力)

眉间皱痕 提交于 2019-11-30 11:27:42
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int a[27],b[27]; int vis[9][9]; int dis[9]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; for(int i=1;i<=m;++i) cin>>a[i]>>b[i]; if(!m)//点数不为7时,可以建立一张完全图 cout<<0; else if(n<7)//点数不为7时,可以建立一张完全图 cout<<m; else{//对于点数为7的情况,可以两个点共用一种点数的牌,所以导致不能猜结论 int ans=0; for(dis[1]=1;dis[1]<=6;++dis[1]) for(dis[2]=1;dis[2]<=6;++dis[2]) for(dis[3]=1;dis[3]<=6;++dis[3]) for(dis[4]=1;dis[4]<=6;++dis[4]) for(dis[5]=1;dis[5]<=6;++dis[5]) for(dis[6]=1;dis[6]<=6;++dis[6]) for(dis[7]=1;dis[7]<=6;+

NOIP2018D2T1 旅行

旧时模样 提交于 2019-11-30 06:35:40
#include<cstdio> #include<set> #include<cstring> int n,m,cnt,mini[500005],ans[500005],u[500005],v[500005]; bool vis[500005]; std::set<int> e[500005]; inline bool cmp(const int *a,const int *b,int now){ for(int i=1;i<=now;i++){ if(a[i]<b[i])return true; if(a[i]>b[i])return false; } return true; } inline void dfs(int u){ vis[u]=1; ans[++cnt]=u; if(!cmp(ans,mini,cnt))return; if(cnt==n){ for(int i=1;i<=n;i++)mini[i]=ans[i]; } for(std::set<int>::iterator it=e[u].begin();it!=e[u].end();it++){ int v=*it; if(!vis[v]){ dfs(v); } } } int main(){ memset(mini,0x3f,sizeof(mini)); scanf("%d%d",&n,&m); for

小w的铁路图「多校联考 2019」

醉酒当歌 提交于 2019-11-30 06:22:28
题意 给定一张有向图,对于每一条边,求删去该边后两端点最短路长度。 思路 数据过水,直接bfs就过了。 代码 #include <bits/stdc++.h> using namespace std; namespace StandardIO { template<typename T>inline void read (T &x) { x=0;T f=1;char c=getchar(); for (; c<'0'||c>'9'; c=getchar()) if (c=='-') f=-1; for (; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0'; x*=f; } template<typename T>inline void write (T x) { if (x<0) putchar('-'),x*=-1; if (x>=10) write(x/10); putchar(x%10+'0'); } } using namespace StandardIO; namespace Project { const int N=1001; int n,m; int cnt; int head[N]; struct node { int to,next; } edge[100001]; int a[100001],b[100001]; int

P1274 魔术数字游戏

守給你的承諾、 提交于 2019-11-30 06:18:13
题目描述 填数字方格的游戏有很多种变化,如下图所示的4×4方格中,我们要选择从数字1到16来填满这十六个格子(Aij,其中i=1..4,j=1..4)。为了让游戏更有挑战性,我们要求下列六项中的每一项所指定的四个格子,其数字累加的和必须为34: 四个角落上的数字,即A11+A14+A41+A44=34。 每个角落上的2×2方格中的数字,例如左上角:A11+A12+A21+A22=34。 最中间的2×2方格中的数字,即A22+A23+A32+A33=34。 每条水平线上四个格子中的数字,即Ai1+Ai2+Ai3+Ai4=34,其中i=1..4。 每条垂直线上四个格子中的数字,即A1j+A2j+A3j+A4j=34,其中j=1..4。 两条对角线上四个格子中的数字,例如左上角到右下角:A11+A22+A33+A44=34。 右上角到左下角:A14+A23+A32+A41=34 输入格式 输入文件会指定把数字1先固定在某一格内。输入的文件只有一行包含两个正数据I和J,表示第1行和第J列的格子放数字1。剩下的十五个格子,请按照前述六项条件用数字2到16来填满。 输出格式 把全部的正确解答用每4行一组写到输出文件,每行四个数,相邻两数之间用一个空格隔开。两组答案之间,要以一个空白行相间,并且依序排好。排序的方式,是先从第一行的数字开始比较,每一行数字,由最左边的数字开始比

错失AK良机的测试48T3 Walk

风格不统一 提交于 2019-11-30 05:37:07
图论一般技巧新建虚点。 新建2^k个虚点。 四种转移。普通点n,新点k。 n->n 1 n->k(自己的) 0 k->k 0 k->n 1 本题bfs,边权为1,则最先扫到最优,要避免重复扫。 使虚点只用来更新一次,只入队一次,从而避免重复考虑。 枚举子集:见小技巧标签的博客。 对于每个点枚举子集,(2^k)^2; 但是要是每个点只扫一次。 发现子集如果扫过,子集的子集一定扫过。 所以每次只考虑下一层子集,放到队列里即可。 O(n+m+2^k) #include<bits/stdc++.h> #define F(i,a,b) for(rg int i=a;i<=b;++i) #define LL long long #define rg register #define il inline #define pf(a) printf("%d ",a) #define phn puts("") using namespace std; int read(); /* 单向双向 */ #define N 300010 #define M 1000010 #define ID 2000010 int n,m,K,val[N],ok[ID]; int to[M],fir[M],head[ID],cnt; il void add(int x,int y){to[++cnt]=y;fir[cnt]

Dungeon Master (luo 三维 BFS )

为君一笑 提交于 2019-11-30 05:23:15
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides. Is an escape possible? If yes, how long will it take? Input The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size). L is the number of levels making up the dungeon. R and C are the number of

codeforces 771 (VK Cup 2017 - Round 1)

回眸只為那壹抹淺笑 提交于 2019-11-30 05:15:21
A. Bear and Friendship Condition •题意 给你n个人,m个朋友关系 朋友是会传递的,若A B是朋友,A C是朋友,则必须有B C的朋友关系 符合这个关系输出YES,否则输出NO •思路 n个人,但凡是有朋友关系的,必定在同一个朋友圈内 所以可以分成若干个朋友圈 在一个朋友圈内部,若符合条件肯定是互为朋友 也就是 是一个完全图 接下来就是判断是否是完全图了 举个栗子:1234在一个朋友圈内,且符合条件 则人与朋友的对应关系为 1与1 2 3 4为朋友 2与1 2 3 4为朋友 3与1 2 3 4为朋友 4与1 2 3 4为朋友 即,他们的朋友是完全相同的! 挨个去判断朋友是否相同显然时间复杂度不够优雅 只需要排序后,看第一个朋友是否相等就可以 O(n)变O(1)! 为什么呢? 因为每个人的朋友圈都要去查看一遍,如果A的朋友圈没有B,但是B的朋友圈有A 那么,B和A的朋友圈肯定对不上,所以就输出NO了 •代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int maxn=2e5+5; 5 vector<int> a[maxn]; 6 //我加vis数组是为了减少不必要的查看来减少时间 7 //氮素 貌似效率还不如不加vis的,搞不懂 ???