[CF1303C] Perfect Keyboard - DFS】的更多相关文章

Solution 根据原字符串建图,每个字符是一个点,相邻则连边 然后从每一个度数为 \(1\) 的点开始爆搜连通块,合法情况下应该是一条链 #include <bits/stdc++.h> using namespace std; #define int long long int g[33][33],d[33],vis[33],fg=1; vector <int> sta; void dfs(int p) { if(vis[p]) return; vis[p]=1; sta.p…
前置芝士 图的遍历:通过DFS或者BFS遍历全图. 前向星:用来存边,但是在本题用也可以用一个二维数组解决. 具体做法 先从判断YES和NO开始,可以发现如果一个字母与三个及以上不同的字母相邻时肯定是不合法的,每个字母与左右的字母连一条边以后如果产生一个长度大于2的环也是不合法的.所以最终合法的图中没有环,没有一个点连出两条以上的边,自然可以发现这就是一堆链了,所以可以从出度为1或0的点开始遍历,如果可以遍历全图自然就没有环了. 代码 #include<bits/stdc++.h> #defi…
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 2626 lowercase Latin letters will be arranged in some order. Polycarp uses the same password ss…
本题可以转换成图论来做,每两个相邻点连一条边,然后统计每一个点的degree,如果>=2说明有一个点要相邻三个点,不满足题意,然后找出每个degree<2的点,这些点可以作为一段的起点,然后依次dfs添加,如果26个字母有一个没有dfs到的,就无解 #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long long LL; ]; ][], vis[]; ];…
A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int main(){ int t;cin>>t; while(t--){ string s;cin>>s; ,f2 = ; ; ; ;i<s.length();i++){ '){ ) { ans+=cnt; cnt = ; f1 = ; } ) f1 = ; } else{ ) c…
A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegm…
比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \(1\) 到最后一个 \(1\) 中间的 \(0\) 全部去掉,也就是它们之间 \(0\) 的个数,那么就顺序.逆序扫一遍就出来了. 代码详解: 点击查看代码 #include<bits/stdc++.h> using namespace std; int main(){ int t; cin&g…
N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with the keyboard is that som…
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=2369">http://acm.hdu.edu.cn/showproblem.php? pid=2369 代码例如以下: #include <cstdio> #include <cstring> char s[1100047]; int hash[247]; int main() { __int64 n; while(~scanf("%I64d",…
有一个筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B管或C管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B管和C管中的球从下往上标号递增. 输入: 第一行输入数据组数N.接下来N行为N组具体数据,每组数据中有10个整数,代表球的放入顺序. 输出: 对于每组数据,若策略存在,输出YES:若不存在,输出NO 解法1:DFS 思路:每次判断当前小球是否大于左边容器的最上端的小球,如果可以就放,否则再去看右边的.一旦发现左右两边都不能放,那就只能判定是NO了.…