随笔 - 530  文章 - 0  评论 - 3  阅读 - 10098 
04 2023 档案
Fib数列的递推
摘要:矩阵快速幂 #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define N 2 int mod; #define int long long struct matrix { int a[ 阅读全文
posted @ 2023-04-30 18:18 towboat 阅读(17) 评论(0) 推荐(0) 编辑
Series-Parallel Networks UVA - 10253
摘要:给定 n,求有多少树满足:任意非叶子节点的儿子不少于 2 , 叶子节点个数为 n 阅读全文
posted @ 2023-04-29 12:31 towboat 阅读(8) 评论(0) 推荐(0) 编辑
Gangsters UVA - 672
摘要:一家饭店,有一扇大小会变得门,变化范围为[0,k]。每过一单位时间你可以让门的大小+1,-1,或者不变。客人会在不同的时间来吃饭,但是如果门的大小和他们希望的值不一样,他们就不会进来并且直接消失。吃饭要花钱,现在问饭店最多能赚多少钱。 F[i ] [j ] =max( F[i-1][j] +v,F[ 阅读全文
posted @ 2023-04-28 19:00 towboat 阅读(8) 评论(0) 推荐(0) 编辑
POJ-1143
摘要:给定一个序列,轮到谁,取出一个数k删除,并删除i*k(i=1,2,3,.....), 设k1为已经删除的数,同时删除k1*i+k*j,(i=1,2,3,.....;j同上 ),轮到谁没数删除时谁就输了。。 求先手取数 可以取那些数字 ,能保证获胜 #include<iostream> #includ 阅读全文
posted @ 2023-04-28 16:51 towboat 阅读(3) 评论(0) 推荐(0) 编辑
UVA10618 跳舞机 Tango Tango Insurrection
摘要:有四个踩踏板,不同的踩踏方式消耗不同的力气 问最小花费的力气 F[ i ] [ a] [b ][ s] , s 是上一次哪只角移动了( 0 ,1,2 ) https://www.luogu.com.cn/problem/UVA10618 #include<iostream> #include <cs 阅读全文
posted @ 2023-04-28 03:07 towboat 阅读(18) 评论(0) 推荐(0) 编辑
UVA10271
摘要:定义一个三元组(a,b,c)(a⩽b⩽c), 它的权值为 (a−b)^2, 给定 n(n⩽5000)n(n⩽5000) 个数,要求选出 k+8 个三元组,使得这k+8个三元组权值和最小。 输入数据是单调递增的。 #include <iostream> #include <algorithm> #in 阅读全文
posted @ 2023-04-27 02:23 towboat 阅读(13) 评论(0) 推荐(0) 编辑
UVA-10688
摘要:有n个苹果,和一个数k,第i个苹果的重量是k+i(1<=i<=n). 已知其中只有一个苹果是甜的,所有比它重量轻的都是苦的,比它重的都是酸的。为了要找出甜的苹果,就要去一个一个地吃它,且吃了咬了苹果就必须把它吃完,不管苹果是苦的还是酸的。例如,先吃#1, 如果#1是甜的,花费1如果#2是甜的,那么选 阅读全文
posted @ 2023-04-27 01:45 towboat 阅读(10) 评论(0) 推荐(0) 编辑
Marbles UVA - 10090
摘要:给定两种购买物品的方案:花费 c1元购买 n1 个物品,或者花费 c2c2​ 元购买 n2n2​ 个物品。 方案可以无限使用,询问购买 n个物品至少要多少元,若无法恰好购买到 n 个物品输出 failed #include <iostream> #include <algorithm> #inclu 阅读全文
posted @ 2023-04-26 21:35 towboat 阅读(26) 评论(0) 推荐(0) 编辑
P1495 【模板】中国剩余定理(CRT)/ 曹冲养猪
摘要:#include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; #define int long long int n,a[20],M[20],Mi[20]; int 阅读全文
posted @ 2023-04-26 18:33 towboat 阅读(3) 评论(0) 推荐(0) 编辑
Hyper-drive UVA - 10542
摘要:题意:给定一些个d维的方块,给定两点,求穿过多少方块 转化为(0,0) 到 (a,b) 先考虑二维的 然后容斥原理 #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace 阅读全文
posted @ 2023-04-26 15:16 towboat 阅读(8) 评论(0) 推荐(0) 编辑
Period UVA - 1371
摘要:题意: 给两个串A,B。现在把B串分为若干个部分,对每一个部分进行操作将其变为一个A串,代价为每部分操作次数的最大值 求最小代价 #include <iostream> #include <algorithm> #include <cstring> using namespace std; cons 阅读全文
posted @ 2023-04-25 19:52 towboat 阅读(15) 评论(0) 推荐(0) 编辑
Moving to Nuremberg UVA12223
摘要:题目大意:给出n,一个无根的树,每条边上都有权值。 现在每个位置都有一个景点,一个人想在一年之内去cnt[ i ] 次景点,所以接下来给出m,表示说在m个位置上有这个人想去的地方,给出位置以及想去的次数(注意,每去一个景点都要返回自己的住处),namo这个人该住在哪里走的路程才最短。 换根dp #i 阅读全文
posted @ 2023-04-25 13:05 towboat 阅读(13) 评论(0) 推荐(0) 编辑
Fast Food UVA - 662
摘要:政府在某山区修建了一条道路,恰好穿越总共m个村庄的每个村庄一次,没有回路或交叉,任意两个村庄只能通过这条路来往。已知任意两个相邻的村庄之间的距离为di(为正整数),其中,0<i<m。为了提高山区的文化素质,政府又决定从m个村中选择n个村建小学(设0<n≤m<500)。请根据给定的m、n以及所有相邻村 阅读全文
posted @ 2023-04-24 22:11 towboat 阅读(14) 评论(0) 推荐(0) 编辑
UVA607
摘要:每节课的长度为 L,有N个主题,讲每个主题的时间分别是 t1,t2,t3..., 每个主题必须在一节课讲完,不能分两节课。一节课可以将多个主题讲完每节课上完有不满意度。 在所需课程数量最少的前提下,求最小不满意度。 #include <iostream> #include <cstring> #in 阅读全文
posted @ 2023-04-24 21:11 towboat 阅读(5) 评论(0) 推荐(0) 编辑
Prime Distance UVA - 10140
摘要:定两个整数 L,R , 求闭区间 [L,R] 中相邻两个质数差值最小的数对与差值最大的数对。 当存在多个时,输出靠前的素数对。 筛 1e6 每个素数,在区间里标记倍数, 类似的还有 https://www.luogu.com.cn/problem/P1835 #include<iostream> # 阅读全文
posted @ 2023-04-24 15:58 towboat 阅读(26) 评论(0) 推荐(0) 编辑
Movie collection UVA - 1513
摘要:有n个影碟,标号为1~n,位置为0~n-1,每次取出一个影碟看完后,将其放在最前面(标号为0处),问每个影碟取出前,其位置之前有多少个影碟 开2倍数组, "i放置前面" 这个操作 add(i,-1) ,add(newi,1) #include<iostream> #include<cstring> 阅读全文
posted @ 2023-04-24 15:29 towboat 阅读(32) 评论(0) 推荐(0) 编辑
Prime k-tuple UVA - 1404
摘要:一个步骤: 在[ a, b] 中标记 S 的倍数 #include<iostream> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int N=1e5+20; const int 阅读全文
posted @ 2023-04-24 13:56 towboat 阅读(14) 评论(0) 推荐(0) 编辑
The Bells are Ringing UVA-12119
摘要:已知M 为T1,T2,T3 的LCM 输出满足 Ti-Tj<=25 的所有可能情况 #include<iostream> #include<cmath> #include<algorithm> #include<cstring> using namespace std; const int N= 1 阅读全文
posted @ 2023-04-23 23:29 towboat 阅读(22) 评论(0) 推荐(0) 编辑
UVA11014
摘要:给定一个NxNxN的正方体,求出最多能选几个整数点。使得随意两点PQ不会使PQO共线。 F(k) #include<iostream> #include<cmath> #include<algorithm> using namespace std; const int N=5e5; #define 阅读全文
posted @ 2023-04-23 19:43 towboat 阅读(8) 评论(0) 推荐(0) 编辑
Gauss Prime UVA - 1415
摘要:#include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N=5e4; int b[N+2], pm[N+2],tot=0; void init(){ b[1]=1; for(int 阅读全文
posted @ 2023-04-23 17:48 towboat 阅读(10) 评论(0) 推荐(0) 编辑
Counting Rectangles UVA - 10574
摘要:给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。 点按照x排序 n^2挑选出 垂直x轴的线段,按照y1排序 #include<iostream> #include<cstring> #include<algorithm> #include<vector> using namesp 阅读全文
posted @ 2023-04-21 23:03 towboat 阅读(14) 评论(0) 推荐(0) 编辑
Eigensequence UVA - 11133
摘要:给你一个递增序列的第一位a1,最后一位an,求有多少个序列满足: 以a1为首,an为尾 1、B(1) = A(1) 2、后面每项满足 A[j]=B[j], A(j-1) < B(j) ≤ A(j), 且bj能整除A(j) - A(j-1)。 F[ i ] [ j ] 最后一位为j 的方案数 #inc 阅读全文
posted @ 2023-04-21 22:09 towboat 阅读(20) 评论(0) 推荐(0) 编辑
组合数取模
摘要:const int N =1e5+4; int fac[N] ,fm[N]; inline int kpow(int a, int b) { int res = 1; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % m 阅读全文
posted @ 2023-04-21 16:56 towboat 阅读(284) 评论(0) 推荐(0) 编辑
Devu and Flowers CF451E
摘要:Devu 有 n 个花瓶,第 ii 个花瓶里有 fi 朵花。他现在要选择 s 朵花。 你需要求出有多少种方案。两种方案不同当且仅当两种方案中至少有一个花瓶选择花的数量不同 可重复集的组合数 Ce( n,m) = C(m-1,m+n-1 ) namo用容斥原理 #include<iostream> # 阅读全文
posted @ 2023-04-21 16:49 towboat 阅读(27) 评论(0) 推荐(0) 编辑
UVA10237 Bishops
摘要:#include <iostream> #include <cstring> #include <queue> using namespace std; const int N=2e5+2; #define int long long int n,m,f1[50][2000] ,f2[50][200 阅读全文
posted @ 2023-04-20 22:04 towboat 阅读(7) 评论(0) 推荐(0) 编辑
Arrange the Numbers UVA - 11481
摘要:求 1∼n 的排列 A 中,满足前 m 个数中,刚好有 K 个数使得 A[ i ]=i 的 AA 的个数。 错位排列 #include<bits/stdc++.h> using namespace std; const int mod=1e9+7; #define int long long int 阅读全文
posted @ 2023-04-20 02:06 towboat 阅读(15) 评论(0) 推荐(0) 编辑
Neon Sign UVA - 1510
摘要:给定空间里的 n 个点,其中没有三点共线。每两个点之间都用红色或黑色的线段连接。 求 3 条边同色的三角形个数。 n≤1000n≤1000。 同色的= 总数- 杂色的 杂色的直接乘法原理就行,但注意ij 和ji 一样 #include <iostream> #include <cstring> #i 阅读全文
posted @ 2023-04-19 20:52 towboat 阅读(10) 评论(0) 推荐(0) 编辑
How Many O's? UVA - 11038
摘要:写下区间[a,b]的所有数 ,问一共有多少个 0 #include <iostream> #include <cstring> #include <vector> using namespace std; #define int long long int n,f[40][40][2][2] ; v 阅读全文
posted @ 2023-04-19 20:12 towboat 阅读(12) 评论(0) 推荐(0) 编辑
Investigating Div-Sum Property UVA - 11361
摘要:定问在[A,B] 中,有多少个整数本身能被m整除,各个数位上数字之和也能被m整除? #include <iostream> #include <cstring> #include <vector> using namespace std; vector<int> a; int m,f[40][105 阅读全文
posted @ 2023-04-19 16:49 towboat 阅读(15) 评论(0) 推荐(0) 编辑
Exploring Pyramids UVA - 1362
摘要:给出一棵树的 dfs 序,求可能的构成方案数。 A______A_______ f[l ][ r] =sum{ f[l+1][k-1] *f[k][j] } #include <iostream> #include <cstring> #include <sstream> using namespa 阅读全文
posted @ 2023-04-18 21:58 towboat 阅读(9) 评论(0) 推荐(0) 编辑
UVA11806 Cheerleaders
摘要:你有一个n×m的网格图,现在你要将K个人放在网格中,满足一下条件: 网格图的四个边都至少有一个人。 每个格子上不能有两个人。 每个人必须都有位置。 注意:四个角的人可以同时算作在两个边上 容斥原理 J=0 时就是 allAnswer #include <iostream> #include <cst 阅读全文
posted @ 2023-04-18 20:59 towboat 阅读(11) 评论(0) 推荐(0) 编辑
Hackers' Crackdown UVA11825
摘要:你需要将 n 个集合分成尽量多组,使得每一组里面所有集合的并集等于全集 3 2 1 2 2 0 2 2 0 1 4 1 1 1 0 1 3 1 2 0 f[S]= max(f[S], f[S-j] +1 ) 且 j是一个包含所有点的集合 #include <iostream> #include <a 阅读全文
posted @ 2023-04-17 23:12 towboat 阅读(13) 评论(0) 推荐(0) 编辑
Robotruck UVA - 1169
摘要:有n个垃圾,第i个垃圾的坐标为(xi,yi),重量为wi。 有一个机器人,要按照编号从小到大的顺序捡起所有垃圾并扔进垃圾桶(垃圾桶在原点(0,0))。 机器人可以捡起几个垃圾以后一起扔掉,但任何时候其手中的垃圾总重量不能超过最大载重C。两点间的行走距离为曼哈顿距离(即横坐标之差的绝对值加上纵坐标之差 阅读全文
posted @ 2023-04-17 21:37 towboat 阅读(11) 评论(0) 推荐(0) 编辑
Add Again UVA - 11076
摘要:define S ,it is sum of all possible permutationsof a given set of digits. For example, if the digits are <1 2 3>, then six possible permutations are<1 阅读全文
posted @ 2023-04-17 21:04 towboat 阅读(12) 评论(0) 推荐(0) 编辑
The Super Powers UVA - 11752
摘要:求1~2^64 区间里, 有多少合法数X 合法数: X= a^b ,至少存在2个不同的a #include <iostream> #include <algorithm> #include <vector> using namespace std; const int N =65536+3; int 阅读全文
posted @ 2023-04-17 20:24 towboat 阅读(18) 评论(0) 推荐(0) 编辑
LCM Cardinality UVA - 10892
摘要:给出n, 求有多少对(a,b) (a<b), 满足 LCM(a,b) =n 暴力求所有因数 #include <iostream> #include <algorithm> #include <vector> using namespace std; const int N =1e4+20; #de 阅读全文
posted @ 2023-04-17 16:35 towboat 阅读(9) 评论(0) 推荐(0) 编辑
Again Prime? No Time. UVA - 10780
摘要:给定 m,n ,求最大的 k 使得 m^k∣n! 分解质因数 #include <iostream> #include <cstring> #include <sstream> using namespace std; const int N =1e4+20; const int inf =1e9 阅读全文
posted @ 2023-04-17 15:45 towboat 阅读(15) 评论(0) 推荐(0) 编辑
UVA10943 How do you add?
摘要:两个数 n,m,求 用 m 个 [0,n] 的整数相加使其和为 n 的方案数。 #include <iostream> #include <cstring> #include <sstream> using namespace std; const int N =102; const int mod 阅读全文
posted @ 2023-04-17 14:57 towboat 阅读(13) 评论(0) 推荐(0) 编辑
UVA11889 Benefit
摘要:lcm(a,b)=c 给a,c ,求最小的b 质因数分解的好题 #include <iostream> #include <cstring> #include <sstream> using namespace std; #define int long long int a,b,c; int cn 阅读全文
posted @ 2023-04-17 02:30 towboat 阅读(9) 评论(0) 推荐(0) 编辑
UVA1392 DNA Regions
摘要:https://www.luogu.com.cn/problem/UVA1392 给定两个长度为 n 的字符串 A 和 B,满足 A 和 B 都只由大写字母 A、C、G、T 组成。 求一个长度最长的闭区间 [L,R],满足对于 i∈[L,R] , 有不超过 p% 的 i 满足 Ai≠Bi 阅读全文
posted @ 2023-04-16 23:20 towboat 阅读(14) 评论(0) 推荐(0) 编辑
Unique Snowflakes uva11572
摘要:找最长的,没有相同元素的区间 双指针 #include <iostream> #include <set> using namespace std; const int N=1e6+2; int n,a[N]; void solve(){ int x=1,y=1,ans=0; set<int> st 阅读全文
posted @ 2023-04-16 22:48 towboat 阅读(4) 评论(0) 推荐(0) 编辑
UVA1451
摘要:二分平均值x,每个数减去x , 找区间 S[ r ]- S[l]>=0 ,r-l>=m #include <iostream> #include <vector> #include <algorithm> using namespace std; const int N=1e5+5; #define 阅读全文
posted @ 2023-04-16 17:35 towboat 阅读(7) 评论(0) 推荐(0) 编辑
Sumsets UVA - 10125
摘要:一个集合中需要找到 a,b,c,d ,使得 a+b+c=d 枚举a,b ,计算a+b,存在map里 再枚举d,c ,计算d-c 是否 存在 d-c==a+b #include <iostream> #include <map> #include <algorithm> #include <vecto 阅读全文
posted @ 2023-04-16 15:53 towboat 阅读(7) 评论(0) 推荐(0) 编辑
Maximum sum on a torus UVA - 10827
摘要:求 n×n 的环状方阵上的最大子矩阵和。 构造 2*n *( 2*n) 的正方形 求余的一个操作 x''= (x-1)%n+1 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const 阅读全文
posted @ 2023-04-16 12:56 towboat 阅读(4) 评论(0) 推荐(0) 编辑
P2467 [SDOI2010]地精部落
摘要:bug: 前缀和不要写错啊啊, 比如 s[r]-s[l-1] #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N=4202; int mod ; int f[N][N 阅读全文
posted @ 2023-04-16 02:40 towboat 阅读(8) 评论(0) 推荐(0) 编辑
UVA1382 Distant Galaxy
摘要:给出平面上的n个点,找一个矩形,使得边界上包含的点尽可能地多。 先维护前缀和 col[i][j],row[i][j] ,表示i行前j个的和。。 枚举上下边界,右边界,考虑维护左边届 #include <iostream> #include <cstring> #include <algorithm> 阅读全文
posted @ 2023-04-15 22:25 towboat 阅读(11) 评论(0) 推荐(0) 编辑
UVA1330 City Game
摘要:利用网格图上空白的方格上建一个矩形的建筑。问地区中建筑物的最大面积 递推(dp) #include <iostream> #include <cstring> #include <sstream> using namespace std; const int N=1e3+2; char a[N][N 阅读全文
posted @ 2023-04-15 20:54 towboat 阅读(11) 评论(0) 推荐(0) 编辑
Fibonacci System UVA - 1652
摘要:https://www.luogu.com.cn/problem/UVA1652 阅读全文
posted @ 2023-04-15 16:01 towboat 阅读(4) 评论(0) 推荐(0) 编辑
UVA11982 名次表的变化
摘要:有两个1~n 的排列A,B, B是1,2,3...n, 给出A每个数位置变化(往后,往前,不变) 问A排列数? 观察以下发现是个二分图匹配的模型,考虑dp f[i ][ j] 考虑前i个,有j个未匹配 #include <iostream> #include <cstring> using name 阅读全文
posted @ 2023-04-15 02:01 towboat 阅读(24) 评论(0) 推荐(0) 编辑
UVA1650 数字串 Number String
摘要:对于任意一个只含数字1~n的有序数字串{a1,a2,……,an},比较数字串中所有相邻数字的大小,后者大于前者的用I表示,否则用D表示。例如,数字串{3,1,2,7,4,6,5},{2,1,3,7,4,6,5}和{3,1,2,7,5,6,4}就表示为'DIIDID'。"?"则表示两数的关系未知。例如 阅读全文
posted @ 2023-04-14 22:49 towboat 阅读(22) 评论(0) 推荐(0) 编辑
Party at Hali-Bula UVA - 1220
摘要:多判断一个唯一性 only[ x] [0/1] #include <iostream> #include <cstring> #include <vector> #include <map> #include <algorithm> using namespace std; const int N= 阅读全文
posted @ 2023-04-14 16:53 towboat 阅读(13) 评论(0) 推荐(0) 编辑
Another Crisis UVA - 12186
摘要:#include <iostream> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N=1e5+3; int f[N],n,K; vector<int> g[N]; 阅读全文
posted @ 2023-04-14 15:18 towboat 阅读(5) 评论(0) 推荐(0) 编辑
Alibaba UVA - 1632
摘要:在一条直线的同一个方向上有 nn 件珠宝,已知每件珠宝的位置,并且第 ii 件珠宝在 Ti时刻消失, 问将所有的珠宝收集起来最小耗时? 搜集不耗时,移动需要耗时 类似区间dp f[i ][ j ] [2] #pragma GCC optimize(2) #include <iostream> usi 阅读全文
posted @ 2023-04-13 22:46 towboat 阅读(12) 评论(0) 推荐(0) 编辑
uva 11082 A Plug for UNIX
摘要:#include <iostream> #include <vector> #include <map> #include <queue> #include <cstring> using namespace std; const int N=1e4+2,M=5e5; int n1,n2,n3,le 阅读全文
posted @ 2023-04-13 20:35 towboat 阅读(5) 评论(0) 推荐(0) 编辑
Calling Circles UVA - 247
摘要:如果两个人相互打电话(直接或间接),则说他们在同一个电话圈里。例如, a打给b,b打给c, c打给d,d打给a,则这4个人在同一个圈里;如果e打给f但f不打给e,则不能推 出e和f在同一个电话圈里。 输入n(n≤25)个人的m次电话,找出所有电话圈。人名只包含字 母,不超过25个字符,且不重复 对于 阅读全文
posted @ 2023-04-13 11:13 towboat 阅读(12) 评论(0) 推荐(0) 编辑
一个研究课题 A Research Problem UVA10837
摘要:输入正整数m(m≤1e8),求最小的正整数n,使得φ(n)=m。n<=2e8。 #include<cstring> #include<algorithm> #include<iostream> #include <map> using namespace std; const int M=1e5+5 阅读全文
posted @ 2023-04-12 21:43 towboat 阅读(20) 评论(0) 推荐(0) 编辑
Semi-prime H-numbers UVA - 11105
摘要:所有形如4n+1(n为非负整数)的数叫H数。定义1是唯一的单位H数, H素数是指本身不是1,且不能写成两个不是1的H数的乘积。 H-半素数是指能写成两个H素数的乘积的H数(这两个数可以相同也可以不同)。 例如,25是H-半素数,但125不是。 输入一个H数h(h≤1000001),输出1~h之间有多 阅读全文
posted @ 2023-04-11 23:17 towboat 阅读(15) 评论(0) 推荐(0) 编辑
python 开数组
摘要:列表推导式~ N=int(10) #二维数组 a=[[j for i in range(N)] for j in range(20)] a[1][1]=8 a[1][2]=2 for i in range(N): for j in range(N): print(a[i][j],end=' ') p 阅读全文
posted @ 2023-04-11 22:29 towboat 阅读(20) 评论(0) 推荐(0) 编辑
Computer Transformation UVA - 1647
摘要:初始串为一个1,每一步会将每个0改成10,每个1改成01,因此1会依次变成 01, 1001, 01101001,… 输入n(n≤1000),统计n步之后得到的串中, “00”这样的连续两个0出现了多少次 f =[0]*1003 g =[0]*1003 f[1]=0 g[1]=1 for i in 阅读全文
posted @ 2023-04-11 22:06 towboat 阅读(13) 评论(0) 推荐(0) 编辑
Zeros and Ones UVA - 12063
摘要:给出n、k(n≤64,k≤100),有多少个n位(无前导0)二进制数的1和0一样多,且值为k的倍数? +=f[i][j][k] #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using nam 阅读全文
posted @ 2023-04-11 18:38 towboat 阅读(11) 评论(0) 推荐(0) 编辑
UVA1646 圈图的匹配 Edge Case
摘要:n个点连成一个圆,求没有公共点的边集的个数 不考虑第n条边 f[n] =f[n-1]+f[n-2] 现在考虑第n条边 ans=f[n]+f[n-2] f=[0]*10005 f[1]=1 f[2]=2 for i in range(3,10004): f[i] =f[i-1]+f[i-2] whil 阅读全文
posted @ 2023-04-11 14:37 towboat 阅读(16) 评论(0) 推荐(0) 编辑
Count UVA - 1645
摘要:f[n] = sum{ f[i] } ( (n-1)%i==0) f[1]=1 #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std ; const int N 阅读全文
posted @ 2023-04-11 13:53 towboat 阅读(16) 评论(0) 推荐(0) 编辑
Divisors UVA - 294
摘要:求区间[L,R]的整数中哪一个的正约数最多。 一个数因数分解后, 它的约数Cnt = (a[j]+1) 的乘积 ,j是每个因数的个数 #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using 阅读全文
posted @ 2023-04-11 12:55 towboat 阅读(8) 评论(0) 推荐(0) 编辑
P1835 素数密度
摘要:给定区间 [L,R](1≤R<(1<<30) R−L≤1e6 ),请计算区间中素数的个数。 筛出 sqrt(R) 的质数p, 遍历 L~R 的数,看能否被p 约分,也就是合数,打个标记 #include <iostream> #include <cstring> #include <cmath> # 阅读全文
posted @ 2023-04-11 12:13 towboat 阅读(26) 评论(0) 推荐(0) 编辑
Perfect P-th Powers UVA - 10622
摘要:给出 n, 写成 n= x^p 的形式,求p最大值 #include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std ; #define int long long int 阅读全文
posted @ 2023-04-10 22:36 towboat 阅读(11) 评论(0) 推荐(0) 编辑
Almost Prime Numbers UVA - 10539
摘要:#include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std ; const int M =1e6+33; #define int long long int b[M] 阅读全文
posted @ 2023-04-10 20:52 towboat 阅读(4) 评论(0) 推荐(0) 编辑
Sum of Consecutive Prime Numbers UVA - 121
摘要:#include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std ; const int M =1e4+33; int b[M],c[M],tot; int s[M] ; 阅读全文
posted @ 2023-04-10 20:29 towboat 阅读(11) 评论(0) 推荐(0) 编辑
Sum of Different Primes UVA - 1213
摘要:选择K个质数,使它们的和等于N。问有多少种方案? 例如,n=24, k=2时有3种方案:5+19=7+17=11+13=24 #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using name 阅读全文
posted @ 2023-04-10 18:50 towboat 阅读(18) 评论(0) 推荐(0) 编辑
Magical GCD UVA - 1642
摘要:对序列A, 求 (j-i+1) * gcd( i, i+1, ... j ) 最大值 G(i) =gcd( G[i-1] ,a[i] ) 即前缀值不升 维护 1~j-1 可能的 i 值 (logn 个) O(n *log^2 #include <iostream> #include <map> #i 阅读全文
posted @ 2023-04-10 18:22 towboat 阅读(13) 评论(0) 推荐(0) 编辑
uva10214 Trees in a Wood.
摘要:类似 https://www.cnblogs.com/towboa/p/17303216.html , 不过给的是n ,m (n<=2000) 枚举 i (1<=i<=n) ,考虑 有多少 j (1<=j<=m) gcd__(i,j)==0 然后分段考虑 (gcd(x,y) = gcd(x,y-x) 阅读全文
posted @ 2023-04-10 16:57 towboat 阅读(10) 评论(0) 推荐(0) 编辑
poj 3090 Visible Lattice Points
摘要:#include<iostream> #include<algorithm> using namespace std; const int M=1e6; int vis[M+4],P[M+4],cnt; int fi[M+4]; void shai(int top){ cnt=0; fi[1]=1; 阅读全文
posted @ 2023-04-10 15:56 towboat 阅读(8) 评论(0) 推荐(0) 编辑
Lighting System Design uva11400
摘要:设计一个照明系统,一共有n(n<=1000)种灯泡可供选择,不同种类的灯泡必须用不同的电源,同一种灯泡则可以用一个,输入为一个n,以下n行,每行四个数值,代表电压V,电源费用K,每个灯泡费用C,所需灯泡数量L。n=0为结束标志。 为了省钱,你可以把一些灯泡换成电压更高的以节省电源的钱,但不能换成更低 阅读全文
posted @ 2023-04-09 22:30 towboat 阅读(11) 评论(0) 推荐(0) 编辑
糖果 Candy uva1639
摘要:有两个盒子各有n (n<=2e5) 个糖,每天随机选一个(概率分别为p,1-p),然后吃一颗糖。直到有一天,没糖了!输入n,p,求此时另一个盒子里糖的个数的数学期望 假设最后某个盒子有 k 颗糖,然后计算概率即可 #include<iostream> #include<cstring> #inclu 阅读全文
posted @ 2023-04-09 17:35 towboat 阅读(9) 评论(0) 推荐(0) 编辑
Crossing Rivers uva12230
摘要:https://www.luogu.com.cn/problem/UVA12230 期望的线性性质 设初始答案 A,为全走陆地的时间 D,则每次输入时去河的长度 L,加上渡河期望时间 2* L/v #include<iostream> #include<cstring> #include<algor 阅读全文
posted @ 2023-04-09 15:58 towboat 阅读(12) 评论(0) 推荐(0) 编辑
Pole Arrangement uva1638
摘要:有高度分别为1到n的n根杆子排成一行。如果你从左侧或右侧看这些杆,较小的杆被较高的杆遮挡。 给出杆子的数量n,从左能看到的杆子数量L,从右能看到的杆子数量R,求杆子有多少种排列方式 考虑高度1~n的柱子, 把高度1的插入 2~i 的某个排列中转移 f[i ][j] [k ]=f[i-1][j-1][ 阅读全文
posted @ 2023-04-09 15:36 towboat 阅读(12) 评论(0) 推荐(0) 编辑
比赛名次 Race uva12034
摘要:两人赛马,最终名次有3种可能 求n人赛马时最终名次的可能性的个数 #include<iostream> #include<cstring> #include<algorithm> #include<set> using namespace std; #define mod 10056 int c[1 阅读全文
posted @ 2023-04-09 12:45 towboat 阅读(7) 评论(0) 推荐(0) 编辑
Critical Mass uva 580
摘要:#include<iostream> #include<cstring> #include<algorithm> #include<set> using namespace std; int f[44],n; signed main() { int i; f[3]=1,f[4]=3; for(i=5 阅读全文
posted @ 2023-04-09 12:06 towboat 阅读(7) 评论(0) 推荐(0) 编辑
纸牌游戏 Double Patience
摘要:记忆化搜索 #include <iostream> #include <cstring> #include <iomanip> using namespace std; double f[5][5][5][5][5][5][5][5][5]; bool v[5][5][5][5][5][5][5][ 阅读全文
posted @ 2023-04-07 17:06 towboat 阅读(5) 评论(0) 推荐(0) 编辑
Headshot UVA - 1636
摘要:#include<iostream> #include<vector> #include<cstring> #include<algorithm> using namespace std; const int N=104; string s; void sov(){ int i; int len=s 阅读全文
posted @ 2023-04-07 15:24 towboat 阅读(3) 评论(0) 推荐(0) 编辑
GCD等于XOR GCD XOR uva12716
摘要:给定一个数字n,如样例所示格式输出满足1<=b<=a<=n且gcd(a,b)==a xor b的(a,b)二元组个数 #include<iostream> #include<vector> #include<cmath> #include<algorithm> using namespace std 阅读全文
posted @ 2023-04-07 02:42 towboat 阅读(12) 评论(0) 推荐(0) 编辑
Choose and divide uva 10375
摘要:求C(i,j)/ C(u,v) 公式化简 筛出所有质数 除法的时候: 因数分解, 求对每个质数的个数的贡献 #include <iostream> #include <cstring> #include <cmath> #include <iomanip> #include <vector> usi 阅读全文
posted @ 2023-04-06 21:17 towboat 阅读(11) 评论(0) 推荐(0) 编辑
uva 12086
摘要:树状数组 1. 求区间和 2. 单点赋值 还是单点改,通过维护一个a[ i ],来求改变值 #include <iostream> #include <cstring> #include <sstream> using namespace std; const int N=2e5+4; int n, 阅读全文
posted @ 2023-04-05 23:15 towboat 阅读(19) 评论(0) 推荐(0) 编辑
Cyborg Genes UVA - 10723
摘要:求一个最短序列,使得输入的两个串的均为他的子序列,同时输出方案数。 n+m-LCS 方案数转移时求 #include <iostream> #include <cstring> using namespace std; #define int long long int n,m; char a[10 阅读全文
posted @ 2023-04-05 22:46 towboat 阅读(10) 评论(0) 推荐(0) 编辑
"Ray, Pass me the dishes!" uva1400
摘要:求区间 [ l,r] 中 的最大子段和 即 Sum[r]-Sum[l] 阅读全文
posted @ 2023-04-05 18:14 towboat 阅读(2) 评论(0) 推荐(0) 编辑
旅行 Tour uva1347
摘要:直角坐标系中,有 nn 个点。要求先从左往右走,再从右往左走,不重复的经过每一个点。 求出最短路径(距离为两点间直线距离)。 f [i ][j ] 表示点 1~max(i,j) 已走过,的路径长度 #include <iostream> #include <algorithm> #include < 阅读全文
posted @ 2023-04-05 16:15 towboat 阅读(12) 评论(0) 推荐(0) 编辑
CF 1807
摘要:https://codeforces.com/contest/1807/problem/G1 easy -version 同《货币系统》 背包 f[ j ] 每个数字合成的次数 #include <iostream> #include <cstring> using namespace std ; 阅读全文
posted @ 2023-04-04 14:53 towboat 阅读(17) 评论(0) 推荐(0) 编辑
Hot Start Up (easy version) CF1799
摘要:你有两个 CPU,n个程序(m个类型)要运行。 在不同条件下程序运行的时间不同,但连续运行的时间满足小于等于在不连续状态下运行的时间。 #include <iostream> #include <cstring> #include <queue> using namespace std; const 阅读全文
posted @ 2023-04-04 14:15 towboat 阅读(37) 评论(0) 推荐(0) 编辑
P2756 飞行员配对方案问题
摘要:一共有n 个飞行员,其中有 m 个外籍飞行员和 (n−m) 个英国飞行员,外籍飞行员从 1 到 m 编号,英国飞行员从 m+1 到 n 编号。 对于给定的外籍飞行员与英国飞行员的配合情况,设计一个算法找出最佳飞行员配对方案,使皇家空军一次能派出最多的飞机。 二分图板子题 用网络流输出时,判断w[i] 阅读全文
posted @ 2023-04-03 22:10 towboat 阅读(18) 评论(0) 推荐(0) 编辑
P1402 酒店之王
摘要:酒店只有P间房间,一天只有固定的 q 道不同的菜,每个房间只能住一位客人,每道菜也只能给一位客人食用。 有一天来了 n个客人,每个客人说出了自己喜欢哪些房间,喜欢哪道菜。 怎么分配,能使最多顾客满意呢? 2 2 2 1 0 1 0 1 1 1 1 二分图, S, 房间,人,食物,T 连边即可 还有, 阅读全文
posted @ 2023-04-03 21:46 towboat 阅读(12) 评论(0) 推荐(0) 编辑
P5343 【XR-1】分块
摘要:f[i ] += f[i-j] j<=100 ( j belong to S 构造的矩阵: 这种求和的柿子可以化为矩阵乘法,做法是 矩阵对应元素设置0/1 #include <iostream> #include <cstring> #include <map> using namespace st 阅读全文
posted @ 2023-04-03 18:31 towboat 阅读(21) 评论(0) 推荐(0) 编辑
P4544 Buying Feed G
摘要:dp &单调队列优化 这个题 : k<=i, 决策点k 可以等于i ,所以在 i 入队后递推 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N =503,M =1e4+2 阅读全文
posted @ 2023-04-03 13:34 towboat 阅读(19) 评论(0) 推荐(0) 编辑
A/B mod
摘要:对分数取模,对B求逆元 (费马小定理实现) #define int long long const int mod =1e9+7; int ksm(int x,int y){ if(y==0) return 1; int t= ksm(x,y/2) ; if(y&1) return ((t*t%mo 阅读全文
posted @ 2023-04-01 22:38 towboat 阅读(35) 评论(0) 推荐(0) 编辑
P2986 Great Cow Gathering G
摘要:换根dp, father -> son , 基本是加减 #include <bits/stdc++.h> using namespace std ; const int N=1e5+2,M=N*5; #define int long long int n,a[N],sz[N],g[N],f[N],S 阅读全文
posted @ 2023-04-01 17:31 towboat 阅读(12) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示