算法
<WRM>
这个作者很懒,什么都没留下…
展开
-
模板生成系统
一、解法一(90分)一定要注意以下几个函数应该传的参数是什么:1.substr(pos,length);2.erase(pos,length);#include<bits/stdc++.h>using namespace std;const int N = 105;struct node { string name; string value;}a[N];string str[N];int main() { int n,m; cin&原创 2022-03-10 11:23:46 · 259 阅读 · 0 评论 -
ccf 节日
本次刷题错误:计算某一天是周几的时候,需要将每一天往后移动一天,因为1850/1/1是周二,顾对7取模之前应该先加一#include<bits/stdc++.h>using namespace std;int isRun(int x) { if(x%400==0||(x%4==0&&x%100!=0)) return 1; return 0;}int day[7] = {1,2,3,4,5,6,7};int mon1[12]={31,28,31原创 2022-03-09 10:46:27 · 208 阅读 · 0 评论 -
ccf 集合竞价
#include<bits/stdc++.h>using namespace std;const int N = 5010;struct node { string t; int flag; int s; double p;}a[N];bool compare(node x,node y) { return x.p<y.p;}int main() { string tt; int n=0; while(原创 2022-03-09 08:05:43 · 218 阅读 · 0 评论 -
字符串匹配
#include<bits/stdc++.h>using namespace std;const int N = 105;int nextT[N];void getNext(string pattern) { int m = pattern.size(); int i = 0; nextT[0] = -1; int t = nextT[i]; while (i < m) { if (t == -1 || pattern[i] == pattern[t]) {原创 2022-02-26 21:05:43 · 152 阅读 · 0 评论 -
命令行选项
#include<bits/stdc++.h>using namespace std;const int N = 30;bool o1[N], o2[N]; //o2为有参数选项,o1为无参数选项string ans[N];int main() { string str; cin >> str; for (int i = 0; i < str.size(); i++) { if (i + 1 < str.size() && st原创 2022-02-26 19:00:15 · 292 阅读 · 0 评论 -
最大的矩形
#include<bits/stdc++.h>using namespace std;const int N = 1010;int h[N];int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &h[i]); } int result = 0; //sort(h+1,h+n+1); for (int i = 1; i <= n;原创 2022-02-22 15:18:16 · 545 阅读 · 0 评论 -
ISBN号码
#include<bits/stdc++.h>using namespace std;int main() { string str; cin >> str; int a[10]; int pos = 0; for (int i = 0; i < str.size(); i++) { if (isdigit(str[i])) { a[pos++] = str[i] - 48; } } int sum = 0; for (int i = 0;原创 2022-02-14 18:06:58 · 281 阅读 · 0 评论 -
csp 窗口
#include<bits/stdc++.h>using namespace std;const int N=50;struct node { int x1,y1,x2,y2; int level; int number;}a[N];bool compare (node x,node y) { return x.level>y.level;}int main() { int n,m; scanf("%d%d",&n,&m); for(i原创 2022-02-14 17:44:45 · 168 阅读 · 0 评论 -
csp 画图
#include<bits/stdc++.h>using namespace std;const int N = 1000;int a[N][N];int main() { int n; scanf("%d", &n); for (int i = 0; i <= 110; i++) { for (int j = 0; j <= 110; j++) { a[i][j] = 0; } } for (int i = 0; i < n;原创 2022-02-14 16:59:46 · 165 阅读 · 0 评论 -
Z字形扫描
#include<bits/stdc++.h>using namespace std;const int N = 5500;int a[N][N];int visited[N][N];int dx[4] = {0, 1, 1, -1};int dy[4] = {1, -1, 0, 1};int result[260000];int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i+原创 2022-02-14 16:30:04 · 361 阅读 · 0 评论 -
csp 数字排序
#include<bits/stdc++.h>using namespace std;const int N=1010;struct node { int cunt; int data;}a[N];bool compare(node x,node y) { if(x.cunt!=y.cunt) { return x.cunt>y.cunt; } return x.data<y.data; }int b[N];int main() { in原创 2022-02-13 22:23:10 · 227 阅读 · 0 评论 -
csp 日期计算
#include<bits/stdc++.h>using namespace std;bool yJudge(int y) { if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) { return true; } return false;}int m1[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //闰年int m2[12] = {31, 2原创 2022-02-13 22:06:27 · 194 阅读 · 0 评论 -
消除类游戏
#include<bits/stdc++.h>using namespace std;const int N = 100;int a[N][N];int b[N][N];//表示(i,j)位置的格子能不能删,能删标记为1,不能删标记为0 int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j+原创 2022-02-13 21:43:54 · 1991 阅读 · 0 评论 -
俄罗斯方块
#include<bits/stdc++.h>using namespace std;int a[20][20];int b[10][10];int main() { int m; for (int i = 1; i <= 15; i++) { for (int j = 1; j <= 10; j++) { scanf("%d", &a[i][j]); } } int pos = 1; for (int i = 1; i <= 4原创 2022-02-13 20:52:04 · 181 阅读 · 0 评论 -
csp 火车购票
注意:当没有相连的座位时,从编号较小的座位依次进行分配#include<bits/stdc++.h>using namespace std;const int N=110;int a[N];int chair[25][10];int sum[25][10];int main() { int n,m; scanf("%d",&n); for(int i=1;i<=20;i++) { for(int j=1;j<=5;j++) { cha原创 2022-02-13 17:53:41 · 129 阅读 · 0 评论 -
csp 工资计算
#include<bits/stdc++.h>using namespace std;int main() { int t; scanf("%d",&t); int s; if(t<=3500) { s=t; } else if(t<=3500+1500-45) { s=(t-105)*100/97; } else if(t<=8000-45-300) { s=(t-455)*10/9; }else if(t<=3500+9000原创 2022-02-13 15:36:15 · 390 阅读 · 0 评论 -
csp 学生排队
#include<bits/stdc++.h>using namespace std;const int N=1010;int a[N];int main() { int n,m; scanf("%d",&n); scanf("%d",&m); for(int i=1;i<=n;i++) { a[i]=i; } for(int i=0;i<m;i++) { int p,q; scanf("%d%d",&p,&q)原创 2022-02-13 14:01:01 · 89 阅读 · 0 评论 -
公共钥匙盒
#include<bits/stdc++.h>using namespace std;const int N = 10010;struct node { int id; int type; int time;} a[N];int q[N];bool compare(node x, node y) { if (x.time != y.time) return x.time < y.time; if (x.type != y.type) return x.t原创 2022-02-13 11:44:45 · 91 阅读 · 0 评论 -
csp 报数游戏
#include<bits/stdc++.h>using namespace std;const int N = 1010;struct node { int pos; int flag;} a[N];int main() { int n, k; int sum = 0; int cunt = 0; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { a[i].pos = i; a原创 2022-02-12 09:43:40 · 2616 阅读 · 0 评论 -
碰撞的小球
#include<bits/stdc++.h>using namespace std;const int N = 110;struct node { int pos; int v;}a[N];int main() { int n,l,t; scanf("%d%d%d",&n,&l,&t); for(int i=0;i<n;i++) { scanf("%d",&a[i].pos); a[i].v=1; } while(t原创 2022-02-11 22:58:41 · 204 阅读 · 0 评论 -
csp 买菜
易错点:在双重循环遍历的时候,可能存在以下情况,所以不能找到时间存在交叉的就停止遍历,还需继续往下寻找#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 5010;struct node { int s; int e;}h[MAXSIZE],w[MAXSIZE];int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++)原创 2022-02-11 20:10:17 · 144 阅读 · 0 评论 -
csp 小明放学
注意:红绿灯凉的顺序:红灯亮完是绿灯,然后是黄灯,以此循环#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 1e5 + 10;struct node { long long k; long long t;} a[MAXSIZE];int main() { int n; long long r, y, g; long long sum = 0; scanf("%lld%lld%lld", &原创 2022-02-11 19:35:25 · 325 阅读 · 0 评论 -
csp 二十四点
#include<bits/stdc++.h>using namespace std;int priority(char c) { if (c == '#') return 0; else if (c == '$') return 1; else if (c == '+' || c == '-') return 2; else return 3;}int calculate(int x, int y, char c) { if (c == '+') { return原创 2022-02-11 10:45:04 · 297 阅读 · 0 评论 -
小明种苹果(续)
#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 1010;struct node { int m; int a[MAXSIZE];} tree[MAXSIZE];int ee[MAXSIZE];int main() { int n; int t = 0, d = 0, e = 0; memset(ee, 0, sizeof(ee)); scanf("%d", &n); for原创 2022-02-10 21:52:48 · 88 阅读 · 0 评论 -
回收站选址
#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 1010;struct node{ int x; int y;}a[MAXSIZE];int dx[8]={-1,-1,-1,0,1,1,1,0};int dy[8]={-1,0,1,1,1,0,-1,-1};int sum[8];int grade[5];int main() { int n; scanf("%d",&n);原创 2022-02-10 19:13:54 · 87 阅读 · 0 评论 -
csp 稀疏向量
#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 5e5+10;struct node { int index; int value;}u[MAXSIZE],v[MAXSIZE];int main() { int n,a,b; scanf("%d%d%d",&n,&a,&b); for(int i=0;i<a;i++) { scanf("%d%d",&原创 2022-02-10 15:25:55 · 211 阅读 · 0 评论 -
风险人群筛查
#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 1e3 + 10;struct node { int x; int y;} a[30][MAXSIZE];int main() { int n, k, t, x1, y1, x2, y2; int cunt = 0, sum1 = 0, sum2 = 0; scanf("%d%d%d%d%d%d%d", &n, &k, &原创 2022-02-10 10:59:17 · 535 阅读 · 0 评论 -
csp 202012-2期末预测之阈值
思路:前缀和#include<bits/stdc++.h>using namespace std;const int MAXSIZE = 1e5+10;struct node { int y; int result;}a[MAXSIZE];bool compare(node xx,node yy) { return xx.y<yy.y;}int sum[MAXSIZE];//前缀和 int main() { int m; scanf("%d",&am原创 2022-02-09 22:44:12 · 215 阅读 · 0 评论 -
ccf-csp 202104-2 邻域均值
本题可以采用差分的方法做,使用数组b[i][j]记录从a[1][1]一直到a[i][j]的和,然后使用双重循环遍历每个(i,j)点,计算出该点的邻域范围有多大右下角为(x2,y2),左上角为(x1,y1),则(i,j)邻域内的所有元素之和就是b[x2][y2] - b[x1][y2] - b[x2][y1] + b[x1][y1]但是,要注意边界情况中(x2,y2)和(x1,y1)的取值#include<bits/stdc++.h>using namespace std;int.原创 2022-02-06 11:08:49 · 604 阅读 · 0 评论 -
前缀和与差分
一、HJ浇花题目链接:https://ac.nowcoder.com/acm/contest/322/M代码:#include<bits/stdc++.h>using namespace std;const int maxsize1 = 1e6+10;const int maxsize2 = 2e5+10;int a[maxsize1];int cant[maxsize2];//cant[i]表示被浇了i次水的花有多少盆 int main() { int n; s原创 2022-02-04 22:00:20 · 772 阅读 · 0 评论 -
最长递增子序列的优化——时间复杂度为O(nlogn)
//最长递增子序列的优化——时间复杂度为O(nlogn)#include<stdio.h>#include<iostream>#include<string>using namespace std;const int MAXN = 1000+10;const int INF = INT_MAX;int support[MAXN];int arr[MAXN];int main() { int n; support[0] = -INF; for原创 2022-01-28 16:11:29 · 574 阅读 · 0 评论