- 博客(67)
- 收藏
- 关注
原创 序列之争1
#include<iostream>#include<vector>#include<algorithm>using namespace std;bool cmp(int a, int b){ return a > b;}int main(){ int n, m; cin >> n >> m; vector<int> v(n, 0); for (int i = 0; i < n; i++) c.
2021-07-09 19:09:03
220
原创 约瑟夫问题进阶
#include<iostream>#include<vector>using namespace std;int main(){ int n, m; cin >> n >> m; vector<int> v(m); vector<int> p(n); for (int i = 0; i < m; i++) cin >> v[i]; for (int i = 0; i < n; i++.
2021-05-30 18:31:55
159
原创 被3整除的数列(动态规划)
#include<bits/stdc++.h>using namespace std;const long long r=1e9+7;int main(){ /* 能被3整除,则数位和为3的倍数 0,1,2 */ /* dp[0][i]->前i个数字组成除3余0的子序列的个数 dp[1][i]->前i个数字组成除3余1的子序列的个数 dp[2][i]->前i个数字.
2021-04-22 21:34:59
291
原创 棋盘(搜索)
#include<iostream>using namespace std;int chess[120][120];int m,n;bool success=false;int answer=100000;/* 1.保证该点是有颜色的 2.向右或向下(坐标范围合法) 2.1有颜色,与该点比较,相同无需操作,不同花费1金币 2.2无色,判断该点是否已经使用过法术,有则跳过 没有,则分两种颜色搜索回溯 3.结束条件,无路可走或到达终点(success) */.
2021-04-21 19:51:12
176
原创 小球排列
#include<iostream>using namespace std;int clo[3];//0,1,2int ans=0;void backtrack(int pre,int num){ /*截止条件: 1.剩余另外两种颜色小球数目<num&&>0*/ //cout<<"function pre: "<<pre<<" num: "<<num<<endl; if(clo[0].
2021-04-17 19:52:33
222
原创 小朋友崇拜之圈
#include<iostream>#include<vector>#include<algorithm>using namespace std;vector<int> fav;vector<int> cur;vector<int>::iterator it;int res=0;bool finshed=false;bool flag;void dfs(int i){ if(finshed) { if(f.
2021-04-16 22:03:46
79
原创 作物杂交
//wrong answer#include<iostream>#include<vector>using namespace std;struct seed{ int seed2; int target;};vector<int> current;vector< vector<seed> > s;vector<int> timeofs;vector<bool> havek;int N,M,K.
2021-04-15 21:19:30
174
原创 解码方法
class Solution {public: int numDecodings(string s) { if (s[0] == '0') return 0; vector<int> dp(s.size()+1); dp[0]=1;dp[1]=1; for (int i =1; i < s.size(); i++) { if (s[i] == '0')//1.s[i]为0的情况 .
2021-04-11 17:56:07
234
原创 走迷宫
#include<iostream>#include<set>#include<vector>using namespace std;const int r=1e4+7;long long w[101][101];int n,m;set<long long> weight;long long sum=0;int dx[2]={0,1};int dy[2]={1,0};void backtrack(int x,int y){ .
2021-04-10 10:46:28
93
原创 最长有效括号
//缺陷:只能针对层层嵌套的括号#define invalid -1class Solution {public: bool ismatch(string& s,int i,int j) { if(s[i]=='('&&s[j]==')') return true; else return false; } int longestValidParentheses(s.
2021-04-09 22:06:04
123
原创 五连珠
#include<stdio.h>#include<string.h>int a[50][50],b[50][50],c[30];int judge(int tep[][50]){ int i,j; int flag=1; for(i=0;i<5;i++) if(tep[0][i]!=0) flag=0; if(flag) return 1; flag=1; for(i=0;i<5;i++) if(tep[1][i]!=0) flag=0.
2021-04-05 21:47:36
221
原创 螺旋矩阵
#include<iostream>#include<string>#include<memory.h>using namespace std;char m[80][80];enum Direction{Right=1,Up,Left,Down};int calculr(int n){ int r=1; while(true) { if(n<=r*r&&n>(r-1)*(r-1)) .
2021-04-05 19:41:47
106
原创 计算相对分子质量
#include<iostream>#include<map>#include<string>#include<stack>using namespace std;map<string,int> elem;int calcul(string& s){ stack<long long> chem; //分别储存括号内数值和括号(用插入0来代替) for(int i=0;i<s.size.
2021-04-05 10:25:53
892
原创 消减整数
#include<iostream>#include<algorithm>#include<vector>using namespace std;vector<int> cnt;void timeofH(long H,long count,long n){ if(H==0) { cnt.push_back(count); }else if(H>0) { if(H<n) .
2021-04-05 08:56:36
141
原创 接雨水
#include<vector>class Solution {/** curwater->现有存水,tolwater->总计存水* 1.查找第一个大于0的点start作为起点* 2.判断start紧接下来的点是否小于该点* 2.1若是,则计算curwater增加,并标记为true* 2.1.1接着判断,小于则增加现有水,大于则结束查找,tolwater增加* 2.2若不是,则该点作为新的start计算*/public: int sto.
2021-04-02 22:09:14
104
原创 校门外的树
#include<iostream>#include<algorithm>#include<vector>using namespace std;struct area{ int left; int right;};bool Cmp(area a, area b){ if (a.left == b.left) return a.right < b.right; else return a.left < b.left;}//排.
2021-04-01 23:48:50
77
原创 苹果摘陶陶
#include<iostream>#include<algorithm>using namespace std;bool Cmp(int a, int b){ return a < b;}int main(){ int n, m; int nsize; int msize; cin >> n >> m; nsize = n; msize = m; int* nptr = new int[n]; int* mptr = n.
2021-04-01 21:52:25
113
原创 储蓄计划(未完全通过)
#include<iostream>using namespace std;int a[13];int main(){ int sum=0,sum2=0; for(int i=0;i<12;i++) { cin>>a[i]; } for(int i=0;i<12;i++) { sum+=300; sum-=a[i]; if(sum<0) .
2021-04-01 21:31:20
93
原创 乒乓球
#include<string>#include<iostream>#include<cmath>#include<algorithm>using namespace std;class score11{private: int score1; int score2;public: score11() { score1 = 0; score2 = 0; } void PrintGame() { cout <&l.
2021-03-31 22:56:01
118
原创 N皇后问题(递归与非递归版本)
#include<iostream>#include <algorithm>using namespace std;/* n个皇后 1.不在同一行 2.不在同一列 3.45度的斜线上,行号差值至少为3 横坐标0~~n-1 纵坐标0~~n-1 每个数只能用一次,枚举 固定x坐标,变换y坐标,全排列,检查是否符合条件*/class Point{ int* Px; int* Py; int n;public: Point() { cin >.
2021-03-28 09:20:45
312
原创 灌溉(队列实现)
/* n行 m列 t出水管 k分钟 1.接收初始水管位置,并初始化计数器为t 2.将初始水管位置入队及每轮结束标志(0,0) 3.依次出队,按方向循环 3.1判断是否合法,合法则计数器加一且入队,不合法则跳过 3.2直至遇到(0,0)表示一轮结束 4.判断是否达到k轮 补:创建二维数组,查看灌溉状态*/#include<iostream>#include<queue>using namespace std;int dx[4] = {-1,1,0,0};.
2021-03-25 23:27:38
104
原创 跑步锻炼(有差错)
/* 2000.1.1 星期六 至2020.10.1 星期四 周一或月初 2千米 其余 1千米 1.时间类包含星期几 2.增加,日期增加,星期几增加 2.1增加时注意闰余年,月份天数 3.判断星期几累加 4.直到目标日期*/#include<iostream>using namespace std;int day[2][13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31, 0,31,29,31,30,31,30,31.
2021-03-22 21:52:31
123
原创 回文日期
#include<iostream>#include<string>using namespace std;int day1[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };int day2[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };/* 解题思路: 1.按回文规则得到新数组 2.判断得到新数组日期是否合法 2.1第一次需判断是否在原日期之后 3.年份.
2021-03-21 20:51:35
135
原创 数字三角形(DP)
#include<iostream>using namespace std;int main(){ int n; cin >> n; int** map = new int*[n]; int** dp = new int* [n]; for (int i = 0; i < n; i++) { map[i] = new int[n]; dp[i] = new int[n]; } for (int i = 0; i < n; i++) { .
2021-03-19 20:00:43
110
原创 阶乘之和(高精度整数)
#include<iostream>using namespace std;class Bigint{private: int digit[1000]; int length;public: Bigint() { for (int i = 1; i < 100; i++) digit[i] = 0; digit[0] = 1; length = 1; }//默认Bigint为0 void initialize(int x) { for (i.
2021-03-19 09:31:02
124
原创 2021年2月7日18:29:12 二叉树基本操作,堕落了几天才敲代码
#include<stdio.h>#include<stdlib.h>struct BinaryTree{ int val; struct BinaryTree* left; struct BinaryTree* right;};struct TreeNode{ struct BinaryTree* node; struct TreeNode* next;};struct Queue{ struct TreeNode* front; struct .
2021-02-07 18:30:19
101
原创 2021年1月28日15:40:40 基于多态的职工管理系统实验(寒假第一个项目,耗时三个半天)
#include<iostream>#include<fstream>#include<string>using namespace std;#include"workermanager.h"#include"worker.h"#include"employee.h"#include"manager.h"#include"boss.h"#define filename "work .txt"//void test()//{// worker* p.
2021-01-28 15:45:11
207
原创 2021年1月27日18:11:41 二进制读写文件
#include<iostream>#include<string>#include<fstream>using namespace std;class person{public: char name[64]; int age;};void test(){ ofstream ofs("person.txt",ios::out|ios::binary); person p = { "black",18 }; ofs.write((const .
2021-01-27 18:13:22
136
原创 2021年1月27日16:28:10 文件读写
#include<iostream>#include<fstream>#include<string>using namespace std;void func(){ cout << "-------------------" << endl;}void test1(){ ofstream ofs; ofs.open("test1.txt",ios::out); ofs << "name:black" <.
2021-01-27 16:28:32
141
原创 2021年1月25日08:53:27
#include<iostream>#include<string>using namespace std;/* 2021年1月25日08:28:31 类 圆类练习,学生类 1.类中的属性和行为 成员 2.属性 成员属性 成员变量 3.行为 成员函数 成员方法 */const double pi = 3.14;class circle{public: int r;//属性 double calculate() { return 2 * r * p.
2021-01-25 08:54:10
117
原创 青牛将隐
青牛将隐题目背景有一即有二,有三即有四。一二三四五,有亦何妨事。题目描述输出一个数列,穿插排列,最大数字为n。具体穿插方式为:开始数列中只有一个数字1,然后每次在数字i两边空隙中增加数字i+1。你可以参照样例来理解题意。格式输入格式一行一个整数n。输出格式一行若干个数字表示答案。样例输入样例13Copy输出样例13 2 3 1 3 2 3Copy数据范围50%1 \leq n \leq 81≤n≤8100%1 \le..
2021-01-24 14:08:15
216
原创 2021年1月24日13:08:09螺旋矩阵
/* 2021年1月24日12:21:58 输出m*n的螺旋矩阵 */#include<stdio.h>#include<stdlib.h>void creatmatrix(int** r,int n,int m){ int x,y; int cnt=1,time=-1;//length->m,width->n printf("creating...\n"); while(1) { time++; for(x=time,y=time;y&.
2021-01-24 13:08:42
170
2
原创 2021年1月24日12:17:37填数游戏
/* 2021年1月24日12:04:42 填数游戏 */#include<stdio.h>#include<stdlib.h>void print(int i,int j,int k){ int x=100*i+10*j+k; int a[10]={0}; int n[3]={x,2*x,3*x}; int r; int flag=1; for(i=0;i<3;i++) { while(n[i]) { r=n[i]%10; a.
2021-01-24 12:18:02
109
原创 2021年1月24日10:27:37 回文数(问题)
/* 2021年1月24日09:08:34 回文数 若一个数(首位不为零)从左向右读与从右向左读都一样,我们就将其称之为回文数。例如:给定一个10进制数56,将56加65(即把56从右向左读),得到121是一个回文数。又如:对于10进制数87:STEP1:87+78 = 165 STEP2:165+561 = 726STEP3:726+627 = 1353 STEP4:1353+3531 = 4884在这里的一步是指进行了一次N进制的加法,上例最少用了4步得到回文数4884。写.
2021-01-24 10:28:36
421
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人