
每日多练
Vincy_King
所有人都祝你快乐,我只愿你遍历山河,觉得人间值得。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【牛客-最短路】KY28 I Wanna Go Home
题目链接 题意 有n个城市,分属两个阵营,两个阵营用1和2表示。第一个城市属于1号阵营,第二个城市属于2号阵营。有一个商人,想要回家,起点为1号城市,终点为2号城市,问这个商人从起点到终点,最少要花费多少时间。(注意:商人只有一次机会从1号阵营的城市前往2号阵营的城市,或者从2号阵营的城市前往1号阵营的城市) 代码 #include <iostream> #include <bits/stdc++.h> #define M 1000 #define INF 999999999 usi原创 2021-08-25 01:08:46 · 138 阅读 · 0 评论 -
【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】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 评论 -
在给定的整数数组中找到重复的数字
方法一 hash表: 时间复杂度是O(n),空间复杂度O(n) public static void main(String[] args) { // TODO Auto-generated method stub int [] data= {2,3,1,0,2,5,3}; HashMap<Integer,Integer> map=new HashMap<>()...原创 2019-11-05 09:43:30 · 1361 阅读 · 0 评论 -
在一个1到100的整数数组中找到丢失的数字
缺少一个数: ①用n(n+1)/2减去所有数之和 缺少一些数: ①标记法:创建一个内存为100的均为NO的数组flag,将原数组中的数作为flag的下标并赋予True值,最后flag中为NO的值为缺失值。 ②将数组排序,前一个数用后一个数减去(最后一个数用101减),如果相差不是1而是n,那么缺失的某一部分为这个数+1…+(n-1) ...原创 2019-11-05 08:27:50 · 2428 阅读 · 0 评论