08 2018 档案
摘要:Paintball这个题可以看作是图上有很多圆形禁区,如果直接考虑是否可以从左边走到右边似乎有些无从下手,其实可以这样考虑,把整个方形区域看作水面,把禁区看作小岛,如果可以从上边沿着这些小岛走到下边的话,就说明方形区域被禁区整个隔断了,那么就不能从左边走到右边,这样一...
阅读全文
摘要:11. Container With Most Water设置两个指针i j ,分别指向首尾两块板,然后向中间移动,那么宽度变小的情况下为了增大面积只有让高度变大,所以每次移动所指板较低的指针,然后计算面积,重复以上过程。int max(int a,int b){ ...
阅读全文
摘要:14. Longest Common Prefixchar s[100000];int min(int a,int b){ return a < b ? a : b;}char* longestCommonPrefix(char** strs, int strs...
阅读全文
摘要:12. Integer to Romanchar s[100];char* intToRoman(int num) { char rs[] = "MDCLXVI"; int ts[] = { 1000,500,100,50,10,5,1 }; int...
阅读全文
摘要:13. Roman to Integerint romanToInt(char* s) { int dic[26]; dic['I'-'A'] = 1; dic['V'-'A'] = 5; dic['X'-'A'] = 10; dic['...
阅读全文
摘要:Parentheses Balance之前脑子可能坏掉了。。。简单的栈的应用,要注意的一个地方是一定要用 fgets ,因为如果是空串的话 scanf 会直接读下一行。#includeusing namespace std;const int maxn = 128 +...
阅读全文
摘要:Tree Reconstruction#includeusing namespace std;const int maxn = 1000 + 5;int n,x,root;int pos[maxn];vectorA[maxn];int main(){ // fr...
阅读全文
摘要:Bandwidth注意节点不一定是按字母表顺序从前到后用的,也有可能是A C 却没用B,因为这个TLE了好几次。。#includeusing namespace std;const int maxn = 26;int L,w;char s[100];int seq[m...
阅读全文
摘要:Krypton Factor注意 && 别写成 & 了。。。#includeusing namespace std;const int maxn = 80 + 5;int n,L,cnt;int A[maxn];int dfs(int cur){ if(cnt+...
阅读全文
摘要:Prime Ring Problem#includeusing namespace std;const int maxn = 17;int n;int A[maxn],vis[maxn],p[2*maxn];int isPrime(int n){ for(int...
阅读全文
摘要:Fractions Again?!x 要用 long long。#includeusing namespace std;const int maxk = 10000;int k;long long x[2*maxk];int y[2*maxk];int judge(i...
阅读全文
摘要:Maximum Product#includeusing namespace std;const int maxn = 20;int n;int seq[maxn];int main(){ // freopen("data.in","r",stdin); ...
阅读全文
摘要:Division#includeusing namespace std;const int maxn = 64 + 5;int n,a[30240][6];int num,kase = 0,cnt = 0;int Pow(int a,int b){ int n ...
阅读全文
摘要:Spatial Structures#includeusing namespace std;const int maxn = 64 + 5;int n,len;int seq[maxn*maxn];char img[maxn][maxn];struct node{ ...
阅读全文
摘要:Patrol Robot这个题还是DFS,不过每个状态除了记录位置之外,还要记录剩余穿越次数,这样一来就变成了三维DFS。对于值为1的点如果剩余穿越次数大于0且该状态未遍历过的话也可以访问。像这种四个方向的话用常量数组比较方便,没必要搞个二重循环,容易出bug。#in...
阅读全文
摘要:Knight MovesBFS即可,字符串数组 size 定义成了 2 导致输入一直错误,应该是无法存入'\0' 引起的,待会儿再深究。#includeusing namespace std;const int maxn = 8;typedef pair P;int ...
阅读全文
摘要:S-Trees#includeusing namespace std;const int maxn = 7;int n,m,t,cnt = 0;char s[2];int a[maxn];char b[maxn];char leaf[int(pow(2,maxn))]...
阅读全文
摘要:Tree Recovery#includeusing namespace std;const int maxn = 30;struct node{ char c; struct node* l = NULL; struct node* r = NUL...
阅读全文
摘要:Sculpture思路:将三维空间网格化,每个长方体占据的所有单元标记为1。求面积的话,DFS所有的单元,依次检查是上下左右前后六个方向上相邻单元是否为1,若否则是表面,面积加+1。求体积的话,从外面某个单元开始DFS,求出外面值为0的单元的个数,那么总单元个数 - ...
阅读全文
摘要:Undraw the Trees这题没啥说的,利用DFS进行先序遍历即可,注意 node 可以不是字母,然后 puts() 默认换行的,太久没用都忘了。。#includeusing namespace std;const int maxn = 200 + 5;int ...
阅读全文
摘要:Ordering Tasks这题比较简单,就是拓扑排序,而且肯定是有向无环图,直接DFS即可。注意数据读取,只要 n 和 m 有一个不为0即可。。。不考虑是否存在环:#includeusing namespace std;const int maxn = 100 + ...
阅读全文

浙公网安备 33010602011771号