7-9 小字辈: 开始使用并查集暴力做的,结果超时。 正确思路: 用嵌套的vector存储每个人的下一辈有谁,之后记录祖宗,再dfs。 之前学STL的时候没学vector,之前学习的dfs也差不多忘了,通过这道题再复习了一下。 代码如下: #include<bits/stdc++.h> using ...
分类:
其他好文 时间:
2020-10-26 11:18:47
阅读次数:
82
C. 如果S不等于1e9的话,可以直接放上k个S,再把剩下的所有数都写成1e9。如果S等于1e9,那么可以把剩下所有的数都写成1; #include <bits/stdc++.h> using namespace std; #define MAXX 1000000000 int n, S, K; i ...
分类:
其他好文 时间:
2020-10-24 09:45:15
阅读次数:
19
Dijkstra是求单源最短路的一种算法,它不能够处理含有负权边的图。本质是递推,依次求出距离起点最近的点。 C++ 板子 #include<bits/stdc++.h> #define ll long long /* 题目链接:https://www.luogu.com.cn/problem/P3 ...
分类:
编程语言 时间:
2020-10-22 22:15:58
阅读次数:
24
比赛链接:https://codeforces.com/contest/1433 #A. Boring Apartments ##题解 模拟即可。 ##代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_wi ...
分类:
其他好文 时间:
2020-10-21 20:39:03
阅读次数:
25
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; typedef pair<int,int> pii; tree<pii,null_type,less< ...
分类:
其他好文 时间:
2020-10-21 20:30:50
阅读次数:
25
#include <bits/stdc++.h> using namespace std; int a[103][103],m; int xx[4]={0,0,1,-1},yy[4]={1,-1,0,0}; int f[103][103]; bool mp[103][103]; void dfs(i ...
分类:
其他好文 时间:
2020-10-20 16:35:04
阅读次数:
25
1 #include<bits/stdc++.h> 2 void quickSort(int a[],int first,int end) 3 { 4 if(first==end) return; 5 int i = first,j = end,temp; 6 while(i<j){ 7 while ...
分类:
编程语言 时间:
2020-10-20 16:26:37
阅读次数:
21
Prime digit replacements 枚举每一位放数字还是放未知的,如果为止的就拿1代替单独存 因为要有8个,所以我们可知未知的一定是三的倍数,末尾一定是1,3,7,然后暴力搞一搞(剪枝跑得飞快) 1 #include<bits/stdc++.h> 2 #define reg regis ...
分类:
其他好文 时间:
2020-10-19 22:57:02
阅读次数:
18
求这个灯管的发光样式种类,发光的部分需连在一起 思路 二进制枚举+检测连通,信誓旦旦地交了个69;事后发现建图的时候少建了一条边,分没了 #include<bits/stdc++.h> using namespace std; const int N=8; int vis[N], light[N]; ...
分类:
其他好文 时间:
2020-10-18 17:13:14
阅读次数:
40
#include<bits/stdc++.h>包含了目前c++所包含的所有头文件 对比: #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include < ...
分类:
编程语言 时间:
2020-10-18 09:59:50
阅读次数:
17