【题意】 【分析】 直接上单位根反演+二项式定理推一波式子即可 【代码】 #include<bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define lson now<<1 #define rson now<<1|1 typedef long long ll; const int mod=
传送门 文章目录 题意:思路: 题意: 给你一个图和若干个边,有些是有向边,有些是无向边,让你给无向边定向,使得最终的图是 D A G DAG DAG。
前言 你说为什么一定要想 \(O(n\log_2n)\) 或者数学做法直接算呢?OI 血统的 \(\tt dp\) 不香吗? 题目 AtCoder 讲解 我们如果知道了三种值的和,以及其对应的前缀方案数,那么就可以很轻松求出答案了。 考虑 \(\tt dp\)。这是一个类似于背包的过程,虽然跟背包好像差的有点远。 令 \(dp_{i
传送门 文章目录 题意:思路: 题意: 思路: 碰到这样的题肯定是先写几个找找规律了,随便写几个就可以发现是以 l c m ( a
想了一堆奇怪的做法,最后通过观察大数据过了。 链接 思路 开始观察 \(border\) 长度盲猜了一个结论,就看在第一个有数值的位置前有几个零,结果错了。 下了数据点后看了一下,发现一段连续后又会出现零,但是似乎每一个合法的字符串在最后都会变回一段从1开始的连续序列,从1一直到字符串结
printf("输出到终端"); // 重定向到文件 freopen("in.txt", "r", stdin); // 清空缓冲区,避免把之前写到终端的字符读进来 fflush(stdin); // 读入文件字符 while(~scanf("%s", &ch)){ // dosomething } // 重定向回终端,mac和linux用这个 freopen("/dev/tty", &q
T1 欧拉筛质数时若 \(i\) 是质数且没有被用过就顺便用于计算结果,复杂度 \(O(n)\) #include<bits/stdc++.h> using namespace std; inline int Rd() { register int x=0; char C=getchar(); for(;C<'0'||C>'9';C=getchar()) ; for(;C>'/'&&C&
题目 hdu5115 题意: 有 n 头狼,打死一头狼,将受到与该狼当前攻击相同的伤害 + 当前相邻狼提供的额外攻击。并且该狼的相邻狼相邻(即有5头狼,打死了第二头狼,那么第一头和第三头相邻)。可以决定击败狼的次序。计算打败所有狼所需的最少伤害。 思路: 在区间[ i ,j ]内:
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; string n; int k, g[10][10]; int d[10]; void floyd() { for (int k = 0;k <= 9;++k) { for (int i = 0;i <= 9;++i) { for (int j = 0;j <= 9;++j) { g
本场难度,略难,主要是难度梯度不均衡外加榜被带歪了。 哈哈,《基础》。 No.721_3 赛提页面 官方题解 F. 对答案一时爽 水,最差一定是0. const int N = 110; char a[N],b[N]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); IOS; i
当数据过多时,可以使用freopen重定向 #include<iostream> using namespace std; int main() { int n; int max = 0; freopen("D:\\cppWorkSpace\\重定向\\Debug\\test.txt", "r", stdin); while (cin >> n) { if (n > max) { max = n
此处本意是输出000000~999999的数字,用来简单的burp暴力破解六位密码,此处主要是为了解决导出密码的问题。 最关键的就简单两行代码 freopen(“in.txt”,“r”,stdin); freopen(“out.txt”,“w”,stdout); //in.cpp #include <stdio.h> int main( ) { freopen("in.txt","r"
open是linux下的底层系统调用函数,fopen与freopen c/c++下的标准I/O库函数,带输入/输出缓冲。 linxu下的fopen是open的封装函数,fopen最终还是要调用底层的系统调用open。 所以在linux下如果需要对设备进行明确的控制,那最好使用底层系统调用(open) open对应的文件操作有:close, rea
一个矩阵,每行、每列都是个排列(置换)。 支持以下操作:总体上下左右位移,每行或列分别取逆置换。 输出一堆操作之后的矩阵。 \(n\le 1000,m\le 10^5\) 一直在想抽象代数,于是一直没有切。 正解比较简单:可以把原矩阵映射到三维空间中:\((i,j,a_{i,j})\)。取逆置换相当于将两维交换。 于是
原题链接 当涉及到频繁地改变元素位置的时候,我们考虑用链表解决问题,这里有两种解决方法 一、STL的List(deque貌似也可) 二、数组模拟链表 两种方法本质都是先找插入位置再插入 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 100010; 4 char word[N]
原题链接 本题属于想到解决方法就会很简单的题目.....但我没想到,第一反应是两层for循环枚举字符串,一看数据范围一定超时,然后又不愿动笔,这题真是活该没做出来555 正确思路: 确实是枚举,但没有必要两层for循环,我们结合substr截取子串再利用map或者set判重即可 1 #in
L2-1 分而治之 (25分) #include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include<cstring> #include<string> #include<map> #include<set> #include<queue> #include<iomanip> #include
Solution 可以发现合法的序列一定由若干个 \(l\),每对相邻的 \(l\) 中间至少夹一个 \(t\) 组成。而对于 \(Lao\),其第一个字符必须为 \(l\)。那么就容易建立出自动机。 对于 \(Lao\),从 \(1\) 号点开始转移;对于 \(Tui\),从 \(3\) 号点开始转移。如果没有转移边就一定不为合法的序列
T4 求最长不下降子序列,因为最大值为150,并且数据产生方式有循环; 所以可以找规律,在后面的时候,每经过一个循环节答案最大值+1; 恶心的事循环节前面和后面的处理,很难调; #include<iostream> #include<cstdio> #include<cstring> #define LL long long using namespace std; const int N=
联赛模拟测试37 阶段排名 27 A 简单题 考场上想出a+b+c是定值且q没啥用,但还是没找到规律 观察式子,将A和B加起来就可以把P消掉 然后每次变化就是A+B和C两个数中大的减小的,小的变两倍 如果C小,C变两倍, 如果C大,\(C=C-(A+B)=C-((A+B+C)-C)=2C-(A+B+C)\),C变两倍减去和,和是
T1 打表找规律发现当2的n次方-1时f(n)=n; #include<iostream> #include<cstdio> #define ull unsigned long long using namespace std; const int N=1e7+7; ull l,r,ans; ull b[100]; int main(){ freopen("dynamic.in","r",stdin); freopen("dyn
经典队内倒二啊 十分经典 感觉有蛮久没训练了 一打起来十分拉跨 Problem A CFGym 100520A Analogous Sets +++ Problem B CFGym 100520B Bayes' Law ??? Problem C CFGym 100520C Catalian Sequences ??? Problem D CFGym 100520D Drunkard's Walk !!! 正解的想法我们想过的 不知
题目下载链接 T1 水题。 # include <bits/stdc++.h> using namespace std; const int N = 100005; int n,k; double gpt[N],a[N],b[N]; void FIO(void) { freopen("sort.in","r",stdin); freopen("sort.out","w",stdout);
OvO 结论为所有边权的和。 至于为什么,我不知道qwq #include<cstdio> #include<cstring> #include<algorithm> #define int long long using namespace std; const int maxn=2e3+1,maxnn=2e6+1; int n; int fa[maxn],ans=0,len1; int C[maxn]; signed main(){ freopen(&q
#include <stdio.h> #include <math.h> #include <string.h> #include <iostream> #include <algorithm> #include<fstream> using namespace std; int a[20][2001]; int b[20][2001]; int main() { int i,j; FILE *stdin1; FILE *stdin2