dfs Codeforces Round #356 (Div. 2) D】的更多相关文章

http://codeforces.com/contest/680/problem/D 题目大意:给你一个大小为X的空间(X<=m),在该空间内,我们要尽量的放一个体积为a*a*a的立方体,且每次放入的立方体的体积要尽可能大,问最多能放几块? 感觉自己还是太菜了...这种题目都做不来TAT 思路:因为每次都要放入,我们找一下情况以后可以发现,假设当前的体积为x,如果要让cnt个数最多,要么就是要减去x-a*a*a,要么就是让x直接等于a*a*a-1,因此我们很容易就可以得到这是一个dfs的条件,…
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <map> #include <queue> #include…
题目传送门 /* DFS:按照长度来DFS,最后排序 */ #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> #include <cmath> #include <vector> using namespace std; ; const int INF = 0x3f3f3f3f; ] = {, }; int a[MAXN]; in…
D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many…
http://codeforces.com/contest/680/problem/E 题目大意:给你一个n*n的图,然后图上的 . (我们下面都叫做‘点’)表示可以走,X表示不能走,你有如下的操作,每次你可以选择一个k*k的框,把其中的所有的X都变成 ‘点’,问在该操作后点相连的数目最多是多少? 没看别人代码和思路自己思考并优化了好久,于是敲了两个多小时...还是代码能力太差了 思路:当然最最单纯的做法就是O(n^4).为了优化,起初想用二维树状数组+并查集的,结果发现窗口中的‘点‘’容易造成…
E. Bear and Square Grid 题目连接: http://www.codeforces.com/contest/680/problem/E Description You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X'). Two empty cells are directly connected if the…
B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|. Limak is a police officer…
A. Bear and Five Cards 题目链接:http://codeforces.com/contest/680/problem/A A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His go…
题目传送门 /* DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 */ #include <cstdio> #include <iostream> #include <cstring> #include <string> #include <map> #include <algorithm> #include <vector> #include <set> #include <…
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a posit…
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance betwee…
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a posit…
D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n cities, numbered 1 through n. There are m bidirectional roads. The i-th road connects two distinct cities ai and bi. No two roads connect the same pair of…
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number - an i…
B. Bear and Finding Criminals 题目连接: http://www.codeforces.com/contest/680/problem/B Description There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|. Limak…
A. Bear and Five Cards 题目连接: http://www.codeforces.com/contest/680/problem/A Description A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) s…
D. Sum in the tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each vertex vv initially had…
C. Bear and Square Grid time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X'). T…
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两点相邻, 那么要不就是踩一脚就破了或者踩一脚走开再走回来踩一脚破了:3. 普通的搜索看是否能到达, 若能还是要讨论终点踩几脚的问题:) DFS 耗时大,险些超时,可以用BFS来做 */ #include <cstdio> #include <algorithm> #include &l…
题目传送门 /* 题意:两点之间有不同颜色的线连通,问两点间单一颜色连通的路径有几条 DFS:暴力每个颜色,以u走到v为结束标志,累加条数 注意:无向图 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <vector> using namespace std; ; co…
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最多上一次,所有客人菜单不能相同.给出三种菜的数量,问最多能接收多少客人. 思路: 一人一道 → 一人两道 → 一人三道. #include <bits/stdc++.h> using namespace std; int main() { int t;cin>>t; while(t--…
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接快速幂 代码 #include<bits/stdc++.h> using namespace std; long long quickpow(long long m,long long n,long long k) { long long b = 1; while (n > 0) { if…
Codeforces Round #177 (Div. 1) A. Polo the Penguin and Strings 题意 让你构造一个长度为n的串,且里面恰好包含k个不同字符,让你构造的字符串字典序最小. 题解 先abababab,然后再把k个不同字符输出,那么这样就是最少 代码 #include<bits/stdc++.h> using namespace std; string s; int main() { int n,k; scanf("%d%d",&am…
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 + .. + ( - 1)n…
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放学我呆到十点然后还要跑回家耽误时间....要不然$D$题就写完了 周末一些成绩好的同学单独在艺术楼上课然后晚上下第一节晚自习和他们在回廊里玩开灯之后再关上一片漆黑真好玩 A.Andryusha and Socks 日常煞笔提.....我竟然$WA$了一次忘了$n<<1$ #include <…
Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define IT set<ll>::iterator #define sqr(x) ((x)*(x)) #define pb…
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Description You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in…
Codeforces Round #499 (Div. 2) https://codeforces.com/contest/1011 A #include <bits/stdc++.h> using namespace std; ]; string s; int main(){ ; sort(a,a+n); ,p=-;i<n&&j<k;i++){ <a[i])r+=a[i],j++,p=a[i]; } cout<<(j==k?r:-); } B #…