- 博客(35)
- 收藏
- 关注
原创 CF903B
题目详情答案#include<iostream>using namespace std;int main(){ int h1,a1,c1,h2,a2; cin>>h1>>a1>>c1>>h2>>a2; int t1=h2/a1; if(h2%a1!=0){ t1++; } int x=(t1-1)*a2-h1; int t2=0; if(x>=0){ t2=x/(c1-a2); t2++; }
2020-12-19 19:35:54
119
1
原创 Kmeans
聚类算法(无监督的数据挖掘算法)作用将数据实现分割用于异常点的监控分类Kmeans聚类K中心聚类谱系聚类EM聚类算法基于密度的聚类基于网格的聚类Kmeans聚类分析利用距离远近的思想将目标数据剧为指定的k个簇,簇类样本越相似,表明簇类效果越好。Kmeans 具体实现从数据中随机挑选k个样本点作为原始的簇中心。计算剩余样本与簇中心的距离,并把各样本标记为离k个簇中心最近的类别。重新计算各簇中样本点的均值,并以均值作为新的k个簇中心。不断重复(2)和(3),直到簇中心
2020-06-13 22:58:46
1812
原创 排列组合模板
一次询问#include<bits/stdc++.h>using namespace std;typedef long long ll;ll work(int n,int m){ if(m>n/2) m = n-m; ll a = 1,b = 1; for(int i=1;i<=m;i++){ a*=n+1-i; b*=i; if(a%b==0) ...
2020-02-22 13:23:59
186
转载 并查集求各集合的元素个数
// 1389.cpp : 定义控制台应用程序的入口点。// 并查集,求每个集合中的元素个数// 在合并时将子树中的结点数目加到根结点 #include "stdafx.h"#include <iostream>#include <cstdio> #define MAX 100000+5 int father[MAX]; //父节点int people...
2019-11-26 19:50:14
1546
原创 P1443 马的遍历
题目大意#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;const int maxn=405;const int I...
2019-11-07 22:05:48
155
原创 P1126 机器人搬重物
题目大意一道有点复杂的bfs题,主要的难点是机器人是在点上,而障碍物在格子里,因为机器人大小确定的⚪,所以我们可以假装把它放到格子里,因此它的范围是x∈[1,n),y∈[1,m)。并且要注意下障碍物的判断条件即可。#include<iostream>#include<cstdio>#include<algorithm>#include<cstri...
2019-11-07 21:39:10
99
原创 P1141 01迷宫
题目大意#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;const int maxn=1e3+5;const int...
2019-11-05 21:56:37
139
原创 P1032 字串变换
题目大意#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;const int maxn=15;const int IN...
2019-11-05 20:46:57
86
原创 CF1256A Payment Without Change
题目大意#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;const int maxn=35;const int IN...
2019-11-05 19:08:15
124
原创 CF1256B Minimize the Permutation
题目大意#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;const int maxn=105;const int I...
2019-11-05 19:05:09
156
原创 cf1256D Binary String Minimizing
题目大意就是要注意一下n的平方超过了10的9次方#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;const int ...
2019-11-05 19:00:19
155
1
原创 P1092 虫食算
题目大意一道很简单的dfs题,只是剪枝方面的要求很高,还有输出完答案要用exit(0)强行跳出,不然会tle#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>using namespace std;in...
2019-10-31 20:46:00
85
原创 p1605 迷宫
题目大意#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 15;int n,m,t,cnt=0;int sx,sy,fx,fy;int a[maxn][maxn];...
2019-10-30 23:32:50
84
原创 P1101 单词方阵
题目大意交题的时候全WA,吓死我了,然后去看了讨论区,才知道字符的输入真是迷,下面这个代码要多加两个getchar()才能AC#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int INF = 0x3f3f3f3f;const int maxn...
2019-10-30 20:12:03
70
原创 P1219 八皇后
题目大意以前大家一直都说八皇后是一道经典的学习dfs的题,学了好多算法之后回来写这个,突然觉得还行。#include<bits/stdc++.h>using namespace std;int a[15],b[15];int n,cnt=0,cot=0;bool flag[15];void dfs(int x){ if(x==n+1){ cnt++; if(co...
2019-10-29 21:11:43
115
原创 P1019 单词接龙
题目大意开始写dfs题了。。。#include<bits/stdc++.h>using namespace std;const int INF=0x3f3f3f3f;char c;int n,ans=1;string s[25];int cnt[25]; void dfs(int x,int len){ int len1=s[x].size(); if(len&g...
2019-10-29 21:07:08
100
转载 种类并查集
种类并查集当我初步了解了并查集之后,发现还有种类并查集,在看了一篇大佬的文章之后,感觉有所收获。下面转载一下此篇文章:原文章作者...
2019-10-22 18:52:24
116
原创 食物链 POJ1182
题目大意一道经典的并查集题目,重点是要思考如果分类。一个物体去分类只能分成被它吃,它本身和它吃的,因此我们将x表示其本身,x+n表示被x所吃,x+2n表示吃x的,开一个3n数组。#include<iostream>#include<algorithm>#include<cstdio>#include<map>#include<sta...
2019-10-20 19:02:17
93
原创 P1996银河英雄传说(加权并查集)
添加链接描述#include<iostream>#include<cstdio>#include<algorithm>#include<vector>#include<cstring>#include<cmath>using namespace std;const int maxn = 3e4+5;int n...
2019-10-08 21:57:45
75
原创 How Many Answers Are Wrong HDU 3038(加权并查集)
做这个题的时候想到了可以用前缀的方法,但是没有想到为什么可以用并查集,后来搜到加权并查集,有点懵,然后想了会儿为什么可以这么写,首先之所以发生冲突是因为前面的区间或者通过前面区间可以推出来的新区间与询问的区间有冲突,所以当我们以某个数即某个节点当作根节点的时候,开个dist数组表示i到其根节点的距离,这是便可以想到用并查集做了。#include<iostream>#include&...
2019-10-08 21:20:25
74
原创 How Many Tables HDU1213
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;const int maxn=1e3+10;int n,m,T;void Init();int Find(int x);void Union(int x,i...
2019-10-08 19:47:43
64
原创 The Suspects poj 1611
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;const int maxn=3e4+10;int f[maxn];int Find(int x);void Union(int x,int y);void...
2019-10-08 19:31:17
60
原创 并查集模板
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;const int maxn=1e5+10;int f[maxn];int Find(int x);void Union(int x,int y);void...
2019-10-08 18:30:32
68
原创 Wireless Network poj2236
题目描述一道很简单的并查集的题目,结果FAIL被写成FAIL,WA了#include<iostream>#include<cstdio>#include<algorithm>#include<map>#include<queue>#include<vector>#include<cstring>#...
2019-09-26 20:37:41
66
原创 CF4D
原文大意#include<bits/stdc++.h>using namespace std;#define pi acos(-1)#define EPS 1e-4const int INF=0x3f3f3f3f;const int maxn = 5005 ;typedef long long ll;vector<int>v;struct node { ...
2019-09-10 22:19:19
148
原创 CF3B
题目大意主要讲的就是给定n个物品,ti表示其体积,pi表示其价值,求在体积不超过v下的价值的最大值,由于体积只有两种,1和2,则可以直接使用贪心做。#include<bits/stdc++.h>using namespace std;#define pi acos(-1)#define EPS 1e-4const int INF=0x3f3f3f3f;const int ...
2019-09-10 20:02:42
146
原创 CF2B(DP+数论)
题目描述首先我们可以想到末尾0的产生,主要是因为2和5相乘得到,所以我们总体思路就是找一条2和5及其倍数最少的路,如果输入的数不包括0的话,因此我们可以找一条路,使其路上每个模2等于0点除2相加的和最小,再找一条路,使其路上每个模5等于0点除5相加的和最小,将两个和进行比较,最终取其较小的那条路。如果输入中含有0的话,那如果走含0的那条路,不管路上其他的数是什么,与零相乘以后最终答案都会是1。...
2019-07-08 13:57:02
2696
原创 CF1C(三角函数和三角形面积的运用)
题目添加链接描述运用的数学知识海伦公式三角行可构成一个外接圆,并且等角多边形可通过圆心角相等得到已知一个等腰三角形边长,求出其顶角的长度(可将其转化成两个直角三角形求得)求一个正n多边形面积,可将其转化成n个小的三角形的和求正n多边形所对应的圆心角,即是求三角形三个圆心角的最大公约数小数求最大公约数的方式#include<bits/stdc++.h>using ...
2019-06-21 12:05:27
508
转载 计算任意多边形的面积
转载自对于凸多边形,很容易计算,如下图,以多边形的某一点为顶点,将其划分成几个三角形,计算这些三角形的面积,然后加起来即可。已知三角形顶点坐标,三角形面积可以利用向量的叉乘来计算。对于凹多边形,如果还是按照上述方法划分成三角形,如下图,多边形的面积 = S_ABC + S_ACD + S_ADE, 这个面积明显超过多边形的面积。该算法还可以优化一下,对上面的式子合并一下同类项S =...
2019-06-21 11:00:20
1149
原创 CF1B(字符串与数字之间的转化)
题目描述之前打训练赛的时候就和队友遇到过给你A,B,C,D,E,F,G等7个字符,他们的排序方式是A,B,C,D,E,F,G,AA,AB…AG…AAA…求给你一个字符串s,求其后面第n个字符串是什么样的。当时想到了将s转化成十进制的数,加上n以后再通过7进制转化回去,但是做的时候转化时总是遇到问题。今天暑假集训刷CF的时候又遇到了,终于弄懂了。重点是模之前要减1,除之前也要减1.AC代码...
2019-06-21 10:43:07
462
原创 UVA253
判断两个正方体旋转以后是否相等判断两个正方体每个面有不同的颜色,在对第二个正方体旋转以后是否和第一个正方体相同。其实方法很简单,就是判断第一个正方体有三个互相垂直的面a,b,c;我们只需要判断这三个面以及与其平行的那个面在另外一个正方形中能找到互不相通的对应的一组面即可。#include<bits/stdc++.h>using namespace std;int main(){...
2019-06-19 09:39:56
585
2
原创 UVA 12657
此题也就是将数据结构课中的双向链表用数组表示,并将其进行运用,做题的过程中遇到的一点小问题就是通过时间复杂度可知,指令4是不能够遍历一次数组的,然后我们发现指令1,2具有相似程度,在翻转一次后,执行指令一,相当于是在没翻转的时候执行指令2。于是可以用一个变量来储存翻转的次数,从而进行解答。在完成指令题的时候,通过UVA12657和UVA101可总结出,我们在完成不同指令之前,要学会去寻找不同指...
2019-06-19 09:39:11
122
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人