
ACM
Vincy_King
所有人都祝你快乐,我只愿你遍历山河,觉得人间值得。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【leetcode】3. 无重复字符的最长子串
题目链接 class Solution { public: int lengthOfLongestSubstring(string s) { //用哈希来记录,有点像是今日的打卡题 unordered_set <char> mp; //mp用来记录最长子串的长度 int len=s.size(); //右指针初始化为-1 int rk=-1,maxlen=0; for(int原创 2021-06-03 11:43:04 · 100 阅读 · 0 评论 -
【leetcode】2. 两数相加
题目链接 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(原创 2021-06-03 11:15:06 · 123 阅读 · 0 评论 -
【leetcode】525. 连续数组
题目链接 class Solution { public: int findMaxLength(vector<int>& nums) { int maxlength=0; int n=nums.size(); unordered_map<int,int> mp;//哈希 int counter=0;//value:值为0 mp[counter]=-1;//index:下标初始化为-1原创 2021-06-03 09:50:29 · 86 阅读 · 0 评论 -
【PAT】1016 Phone Bills (25 分)
题目链接 #include <iostream> #include <bits/stdc++.h> using namespace std; double timm[24]; struct per{ string name; int d,h,m,M; string state; }p[1010]; bool comp(per &a,per &b){ if(a.name==b.name){ if(a.d==b.d){原创 2021-06-02 20:39:08 · 87 阅读 · 0 评论 -
【PAT】1003 我要通过! (20 分)
题目链接 菜鸟做法 #include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int n; string a; cin>>n; //观察之后,会发现一个规律 //前面的A的数量×中间的A的数量=最后的A的数量 while(n--){ cin>>a; //除了PAT外没有别的字母原创 2021-05-31 14:45:10 · 159 阅读 · 0 评论 -
【PAT】1015 Reversible Primes (20 分)
题目链接 数组 #include <iostream> #include <bits/stdc++.h> using namespace std; int arr[100010]; bool check(int n){ if(n==1) return false; for(int i=2;i<=sqrt(n);i++){ if(n%i==0){ //cout<<i<<endl;原创 2021-05-28 21:45:46 · 116 阅读 · 0 评论 -
【PAT】1014 Waiting in Line (30 分)
题目链接 #include <iostream> #include <queue> using namespace std; struct Customer { int cost_time, start_time, end_time; } customer[1001]; int main() { // n个窗口,每个窗口到黄线,最多排m个人,k个客户,有q个客户想知道他啥时候被服务结束 int n, m, k, q; cin >> n原创 2021-05-28 19:49:38 · 70 阅读 · 0 评论 -
AcWing【4. 多重背包问题 I】
题目链接 #include <iostream> #include<bits/stdc++.h> using namespace std; int dp[1010],v[1010],w[1010],s[1010]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>v[i]>>w[i]>>s[i];原创 2021-05-27 01:21:02 · 81 阅读 · 0 评论 -
AcWing【3. 完全背包问题】
题目链接 #include <iostream> #include<bits/stdc++.h> using namespace std; int dp[1010],v[1010],w[1010]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>v[i]>>w[i]; } for(int i=1;i原创 2021-05-27 01:00:31 · 95 阅读 · 0 评论 -
AcWing【2. 01背包问题】
题目链接 一定要记住等于号! 二维数组 #include <iostream> #include<bits/stdc++.h> using namespace std; int dp[1010][1010],v[1010],w[1010]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>v[i]>>w[i];原创 2021-05-26 23:26:17 · 142 阅读 · 0 评论 -
【PAT】1013 Battle Over Cities (25 分)
题目链接 题解 本题的实质是,在一个连通分量中抹去一个点和他的所有边,要求你求出还至少需要多少条边能让整个图重新变成一个连通分量,也就是连通分量的个数-1;注意,每检测一个城市之前,需要对visit数组进行一次初始化。 代码 #include <iostream> #include <bits/stdc++.h> using namespace std; const int INF=1000000000; vector<int> G[1010]; int m,n,k; i原创 2021-03-13 08:25:19 · 180 阅读 · 0 评论 -
【PAT】1010 Radix (25 分)
题目链接 题解 参考博文 代码 #include <iostream> #include <bits/stdc++.h> using namespace std; // 根据进制,把字符串转为实际数字 long long convert(string num,long long radix){ long long res=0; int exp;//最低位的指数 // auto自动判断类型,rbegin()是最后一个字符,rend()是第一个字符 fo原创 2021-03-12 17:02:47 · 112 阅读 · 0 评论 -
【PAT】1012 The Best Rank (25 分)
题目链接 题解 map+结构体 代码 #include <iostream> #include <bits/stdc++.h> using namespace std; int temp; struct stu { string id; int c,m,e,a; int cc,mm,ee,aa; } per[3000]; bool compare(stu x,stu y) { if(temp==1) { return x.a&原创 2021-03-12 10:43:31 · 104 阅读 · 0 评论 -
【PAT】1009 Product of Polynomials (25 分)
题目链接 题解 这道题主要犯了两个错误,一个是没有考虑到第二个多项式只有一个项的情况;另一个是没有考虑到如果某个指数所对应的系数为0是不用输出的,且最后也不包括在输出给多项式的个数内。 代码 #include <iostream> #include <bits/stdc++.h> using namespace std; int m,n,e[1010],x; double c[1010],y,a[2010]; int main() { cin>>m;原创 2021-03-08 16:43:24 · 111 阅读 · 0 评论 -
【PAT】1007 Maximum Subsequence Sum (25 分)
题目链接 题解 刚开始一看到最大字段和和同时输出字段的起始和终止位置i和j就没看仔细看下去了,后来才发现:是输出最大和加最大字段和起始处的数字和结束位置的数字 ; 如果整个数列全部为负数,则最大和为 0,字段和的起始位置为 0,终止位置为 n - 1 ; 一共有两种方法,第一种是暴力搜索,第二种是动态规划,以下用的是动态规划。 代码 #include <iostream> #include <bits/stdc++.h> using namespace std; int mai原创 2021-03-08 15:40:48 · 147 阅读 · 0 评论 -
【PAT】1005 Spell It Right (20 分)
题目链接 最简单的一题,直接 上代码 代码 #include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; const int maxx=101; string a; string c[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; int main() {原创 2021-03-02 11:07:41 · 98 阅读 · 0 评论 -
【PAT】1004 Counting Leaves (30 分)
题目链接 题解 第一行输入节点数N和非叶子节点数M,接下来的M行输入结点ID,在结点ID中所包含的孩子的个数K,接下来K个输入孩子节点的ID。看了好多遍才看懂,理解能力是真的菜。 DFS #include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; const int maxx=101; vector<int> Node[maxx]; int num[ma原创 2021-03-02 10:49:43 · 88 阅读 · 0 评论 -
【PAT】1002 A+B for Polynomials (25 分)
题目链接 题解 这道题的思路其实很简单,不用专门把a和b都给算出来,只要把a和b中指数相同的系数相加就可以了,幸亏N的范围不大,遍历一次不算耗时。有两个细节需要注意一下:① 系数保留一位小数; ② 每行最后的输出不要有空格。 代码 #include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; const int maxn=1010; double b[maxn];原创 2021-03-02 10:05:09 · 104 阅读 · 0 评论 -
【PAT】1001 A+B Format (20 分)
题目链接 题解 能把题目看错的我也是醉了,其实整体的意思就是把a+b的结果转换成三位小数的浮点数,就在倒数第三位前加上逗号。 代码 #include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; int main() { int a,b; cin>>a>>b; string c=to_string(a+b); i原创 2021-03-01 20:52:16 · 107 阅读 · 0 评论 -
【PAT】Highest Price in Supply Chain (25)
题目链接 题解 本菜鸡刷题太少,虽然题目很简单,倒也是看了半天。题目意思大概如下:给出N个结点,P是单价,r是每次转手价格上升的百分比,然后第二行给出N个数(结点下标从0~N-1),每个数代表着第i个结点的供应商(也就是第i个结点的父亲,比如第一个数是1,就说明1是0的父亲,第二个数是5,就说明5是1的父亲),如果是-1,就代表那个点是根结点。 可以用DFS对叶子结点进行搜索,如果记录到了比最高单价还要高的价格,就进行更新,并记录最高单价的叶子数num=1;若计算出来的单价和最高单价一样,则num++。 代原创 2021-03-01 00:03:42 · 170 阅读 · 0 评论 -
【CCF】201812-2小明放学
题目描述 思路 这道题是和第一题有联系的,输入时依次输入r,y,g,但是在红绿灯的顺序却是r,g,y,所以在刚开始输入的时候要按照红绿灯的顺序进行输入,这样方便之后的计算。定义一个time数组对其进行存储,下标之所以用0,1,2而不是1,2,3是因为在之后的红绿灯变化中可直接通过a=(a+1)%3;来进行更新。 这道题最主要就是要求出当小明到路口时所遇得到的红绿灯正处于哪种状态,起初傻傻的我直接...原创 2019-12-15 09:46:14 · 235 阅读 · 0 评论 -
【CCF】 损坏的RAID5
#include<cstdio> #include<cstdlib> #include<cstring> #include<cctype> #define N 1005 #define MAXL 81925 int n;//阵列中硬盘的数目 int s;//条带的大小(单位:块,1块是4个字节),8个字符 int l;//现存的硬盘数目 ...原创 2019-12-10 12:03:59 · 214 阅读 · 0 评论 -
【CCF】小中大
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int a[100010]; int main(){ int n,maxx,minn; cin>>n; for(int i=0;i<n;i++){ ...原创 2019-12-10 00:35:51 · 119 阅读 · 0 评论 -
【CCF】字符画
转载代码+个人见解 #include <iostream> #include <string> #include <vector> #include <iomanip> #include <sstream> using namespace std; unsigned char pixel[1080][1920][3]; //记录图...原创 2019-12-07 01:05:01 · 826 阅读 · 0 评论 -
【CCF-CSP】小明种苹果(续)
纪念一下被此道题给坑了,count那里不能直接在if(sum[i]>a[i][j])里面进行++,不能会重复,所以要立个flag #include <iostream> #include <cstdio> using namespace std; int a[10000][10000],b[10000],sum[10000]; int main() { // ...原创 2019-12-05 18:19:53 · 220 阅读 · 0 评论 -
Firetruck
题目描述 中心城市消防部门与运输部门合作,维护反映城市街道现状的城市地图。消防员需要能够选择从火警站到火警的路线。 中心城市分为不重叠的消防区。当报告发生火灾时,中央调度员通知火灾发生地区最近的火警站,并列出可能路线。您必须编写一个程序,中央调度员可以使用该程序来生成从地区火警站到火灾的路线。 输入 消防区都用小于 21 的正整数来标识,而且火场始终位于第一个消防区。输入文件包含多个测试用例,代表...原创 2019-10-29 20:20:36 · 172 阅读 · 0 评论 -
Fractions Again?!
这题就是直接暴搜,代码如下 #include <bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n){ int a[10010],b[10010]; int i=0,j,x,y; for(y=n+1;y<=2*n;y++){ if((y*n)%(y-n)==0)...原创 2019-10-29 19:37:40 · 189 阅读 · 0 评论 -
Zombie’s Treasure Chest
Zombie’s Treasure Chest 这道题一看就用了完全背包,结果毫无疑问的挂了,看了一些大佬的解析后,发现有两种做法,一种是直接列举,另一种是通过最小公倍数的方法。 题意 有一个体积为N的箱子和两种数量无限的宝物。 宝物1的体积为S1,价值为V1;宝物2的体积为S2,价值为V2。你的任务是计算最多能装多大价值的宝物。 思路 枚举一:当s1和s2的体积很小,N很大的时候,由题意可知:s...原创 2019-10-28 12:12:04 · 204 阅读 · 0 评论 -
HDOJ 1443 Joseph
HDOJ 1443 Joseph #include <cstdio> #include <iostream> using namespace std; int a[15]; void Josphus(){ int k,m,s,x,len; for(k=1;k<14;k++){ for(m=k+1;;m++){ x=0;len=2*k; while...原创 2019-10-16 12:38:12 · 145 阅读 · 0 评论 -
KMP算法
KMP参考网址原创 2019-10-15 23:34:29 · 327 阅读 · 1 评论 -
数字三角形
P1216 [IOI1994][USACO1.5]数字三角形 Number Triangles 先来一题热热身 题目描述 观察下面的数字金字塔。 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大。每一步可以走到左下方的点也可以到达右下方的点。 7 3 8 8 1 0 2 7 4 4 4 5 2 6...原创 2019-09-24 17:17:19 · 179 阅读 · 0 评论 -
SCNUSE 9月训练专题
#include <iostream> #include <cstdio> #include <queue> #include <cstring> using namespace std; char a[100110]; deque<char> q; int main(){ while((scanf("%s",a))!=EOF)...原创 2019-09-23 13:30:56 · 312 阅读 · 0 评论 -
dfs||bfs迷宫集合
师兄在蓝桥杯培训的时候讲过dfs,但是但是后来又忘了,然后又做,现在又忘//希望师兄不要打我 #include <iostream> #include <cstdio> #include <vector> #include <queue> #include <algorithm> #include <cstring> u...原创 2019-09-17 19:33:19 · 120 阅读 · 0 评论 -
2019ICPC(南昌) Fire-Fighting Hero(最短路)
点这里获取链接 题目大意 有一个由n个点,m条边组成的无环无向图,题目保证是连通图,现在每个点代表一个着火点,有一个消防英雄和k个消防队伍比赛救火,他们的具体位置输入时会给出,谁的分数低谁就获胜,分数的定义如下: 消防英雄:到每个着火点的最短路中的最大值除以题目中给出的C,最后为了避免出现浮点数,消防英雄除以C,变成消防队伍乘以C即可,爆不了int。 消防队伍:从k个队伍中选择最优的一个消防队伍(...原创 2019-09-11 14:14:46 · 199 阅读 · 1 评论 -
双向队列
双向队列含义STL例题一【Magic Master】 含义 (deque,全名double-ended queue)是一种具有队列和栈的性质的数据结构。双端队列中的元素可以从两端弹出,其限定插入和删除操作在表的两端进行。 双端队列是限定插入和删除操作在表的两端进行的线性表。这两端分别称做端点1和端点2。也可像栈一样,可以用一个铁道转轨网络来比喻双端队列。在实际使用中,还可以有输出受限的双端...原创 2019-09-11 11:31:16 · 629 阅读 · 0 评论 -
【AC自动机】
AC自动机——多模式串字符匹配法AC自动机介绍字典树Trie关键点三:文本串的匹配模板详解【HDU2222】经典例题蓝桥杯【算法训练】 Password Suspects AC自动机——多模式串字符匹配法 AC自动机介绍 该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之一。一个常见的例子就是给出n个单词,再给出一段包含m个字符的文章,让你找出有多少个单词在文章里出现过。在...原创 2019-09-07 22:09:29 · 198 阅读 · 0 评论