HAPPY2020暑假训练前复习

A.计蒜客 - T1381

输出hello world
万恶之源

B.51Nod - 2060

全排列输出
不要用STL的next_permutation,会超时

#include <bits/stdc++.h>
using namespace std;
const int maxn=14;
int dt[maxn];
int vis[maxn];int n;
void dfs(int depth)
{if(depth==n){for(int i=0;; ++i){if(i==n)break;if(i==0)cout<<dt[i];else cout<<" "<<dt[i];}cout<<endl;return ;}for(int i=1; i<=n; ++i){if(vis[i]==0){vis[i]=1;dt[depth]=i;dfs(depth+1);vis[i]=0;}}
}
int main()
{cin>>n;dfs(0);return 0;
}

C HDU - 1715

求斐波那契数列(不过比较大到1000)
用数组来存每一位,模拟进制运算

#include<iostream>
#include<cstdio>
#include<cstring>typedef long long LL;
using namespace std;
int f[1005][605];void init()
{f[1][0] = f[2][0] = 1;f[1][1] = f[2][1] = 1;int len = 1;for(int i = 3;i <= 1000;i ++){for(int j = 1;j <= len;j ++){f[i][j] += f[i-1][j] + f[i-2][j];if(f[i][j] >= 10){f[i][j+1] += f[i][j] / 10;f[i][j] %= 10;}}while(f[i][len+1]) len ++;f[i][0] = len;}
}int main()
{int n, t;init();scanf("%d",&t);while(t --){scanf("%d",&n);for(int i = f[n][0];i >= 1;i --)printf("%d", f[n][i]);printf("\n");}return 0;
}
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long ll;
int main(){int n,q,i,j,temp=0;cin>>q;while(q--){cin>>n;char a[10010]="1",b[10010]="1",c[10010]={0};for(i=0;i<n-2;i++){int len=max(strlen(a),strlen(b));for(j=0;j<len;j++){   //模拟加法temp=0;if(a[j]>='0'){    //短的数不加temp+=a[j]-'0';}if(b[j]>='0'){temp+=b[j]-'0';}if(temp>=10){      //判断进位if(c[j]>='0'){c[j]+=temp-10;}else{c[j]+=temp-10+'0';}c[j+1]=1+'0';}else{if(c[j]>='0'){if(temp==9){   //若前位进位了,而且加上的数字是9,那么还要进位!!!c[j]='0';c[j+1]='1';}else{c[j]+=temp;}}else{c[j]+=temp+'0';}}}strcpy(a, b);strcpy(b, c);memset(c, 0, sizeof(c));}int len=strlen(b);for(i=len-1;i>=0;i--){  //倒着输出printf("%c",b[i]);}printf("\n");}return 0;
}

D POJ - 2251

三维迷宫BFS搜就完事了

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
const int maxn=32;
struct node
{int x;int y;int z;int step;
} start,fin; 
char a[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];int dx[]={0,0,1,-1,0,0};
int dy[]={1,-1,0,0,0,0};
int dz[]={0,0,0,0,1,-1};int l,r,c;bool flag=false;
queue<node> q;void bfs()
{while(q.size()) q.pop();memset(vis,false,sizeof(vis));q.push(start);vis[start.x][start.y][start.z]=true;while(!q.empty()){node temp=q.front();q.pop();	if(temp.x==fin.x && temp.y==fin.y && temp.z==fin.z){flag=1;printf("Escaped in %d minute(s).\n",temp.step);return ;}for(int i=0;i<6;i++){node next;next.x=temp.x+dx[i];next.y=temp.y+dy[i];next.z=temp.z+dz[i];if( next.x>=0&&next.x<l && next.y>=0&&next.y<r && next.z>=0&&next.z<c &&!vis[next.x][next.y][next.z] && a[next.x][next.y][next.z]!='#'){vis[next.x][next.y][next.z]=true;next.step=temp.step+1;q.push(next); }		} }
}
int main()
{while(cin>>l>>r>>c){if(l==0&&r==0&&c==0){break;}for(int i=0;i<l;i++){for(int j=0;j<r;j++){for(int k=0;k<c;k++){cin>>a[i][j][k];if(a[i][j][k]=='S'){start.x=i;start.y=j;start.z=k;start.step=0;}if(a[i][j][k]=='E'){fin.x=i;fin.y=j;fin.z=k;fin.step=0;}}}}	flag=0;bfs();	if(!flag){cout<<"Trapped!"<<endl;	} }return 0;
}

E 计蒜客 - T2028

跳石头,经典二分题目, noip原题

#include<bits/stdc++.h>
using namespace std;
long long int a[50004];long long int d,n,m;
bool judge(int x){int tot=0;int i=0;int now=0;while(i<n+1){i++;if(a[i]-a[now]<x)tot++;else now=i;}if(tot>m)return 0;else return 1;
}
int main()
{cin>>d>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];} a[n+1]=d;int l=1;int r=d;int ans;while(l<=r){int mid=(l+r)>>1;if(judge(mid)){l=mid+1;ans=mid;}else r=mid-1;}cout<<ans<<endl;
}

F HDU - 1702

#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
void cnd(int sum,bool f)
{if(f==1){//先进先出 queue<int>q;string a;int b;for(int i=1;i<=sum;i++){cin>>a;if(a[0]=='I'){cin>>b;q.push(b);}else {if(q.empty()){cout<<"None"<<endl;}else {cout<<q.front()<<endl;q.pop();}}}while(!q.empty())q.pop();}else{stack<int>s;string a;int b;for(int i=1;i<=sum;i++){cin>>a;if(a[0]=='I'){cin>>b;s.push(b);}else {if(s.empty()){cout<<"None"<<endl;}else {cout<<s.top()<<endl;s.pop();}}}while(!s.empty())s.pop();}}
int main()
{int n;cin>>n;int a;string s;for(int i=1;i<=n;i++){cin>>a>>s;
//		cout<<s[0]<<endl;bool f;if(s[2]=='F')f=1;//先进先出 else f=0;cnd(a,f); }return 0;
}

G POJ - 1011

详细题解

H POJ - 3494

求最大全1子矩阵的面积
题解

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;const int MAXN = 2007;
int n,m;
int h[MAXN],s[MAXN],L[MAXN],R[MAXN];int solve()
{int t = 0;for(int i = 0; i < m; ++i){while(t > 0 && h[s[t-1]] >= h[i])t--;if(t == 0) L[i] = 0;else L[i] = s[t-1]+1;s[t++] = i;}//找最左边 t = 0;for(int i = m-1; i >= 0; --i)//最右边 {while(t > 0 && h[s[t-1]] >= h[i])t--;if(t == 0) R[i] = m-1;else R[i] = s[t-1]-1;s[t++] = i;}int ret = 0;for(int i = 0; i < m;  ++i)ret = max(ret,h[i]*(R[i]-L[i]+1));return ret;
}int main()
{int num;while(~scanf("%d %d",&n,&m)){memset(h,0,sizeof(h));int res = 0;for(int i = 0; i < n; ++i){for(int j = 0; j < m; ++j){scanf("%d",&num);if(num==1)h[j]++;else h[j]=0;}res = max(res,solve());}printf("%d\n",res);}return 0;
}
/*
4 5
0 1 1 0 1
0 1 1 1 1
0 0 1 1 0
0 0 1 1 1
*/ 
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring> int n,m,ans;int map[2333][2333];int h[2333][2333],sta[2333],L[2333],R[2333];//h[i][j]:第i行第j列元素往上最长的连续1长度//维护单调非递减栈void init(int row){int top = 0,tmp;h[row][m+1] = 0;for(int j = 1;j <= m + 1;j ++) {while(1) {tmp = sta[top];if(h[row][tmp] <= h[row][j]) break;//以j作为延伸点,确定边界,保证单调性。 R[tmp] = j;-- top;}L[j] = tmp;sta[++top] = j;}for(int j = 1;j <= m;j ++) {if(map[row][j] == 0) continue;int len = R[j] - L[j] - 1;ans = max(ans,h[row][j] * len);}}int main(){while(scanf("%d%d",&n,&m) != EOF) {for(int i = 1;i <= n;i ++) {for(int j = 1;j <= m;j ++) scanf("%d",&map[i][j]);}memset(h,0,sizeof(h));for(int j = 1;j <= m;j ++) {for(int i = 1;i <= n;i ++) {if(map[i][j] == 1) {h[i][j] = 1;while(map[++i][j] == 1) h[i][j] = h[i-1][j] + 1;-- i;}}}ans = 0;for(int i = 1;i <= n;i ++) init(i);printf("%d\n",ans);}return 0;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/319899.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【LCT】洞穴勘测(luogu 2147/金牌导航 LCT-1)

洞穴勘测 luogu 2147 金牌导航 LCT-1 题目大意 给你若干操作&#xff0c;有三种操作&#xff1a; 1.连接两个点 2.吧两个点之间的连边断掉&#xff08;保证有这条边&#xff09; 3.查询两个点之间是否连通 样例 #1 输入样例 #1 200 5 Query 123 127 Connect 123 127 Que…

Service Fabric 与Ocelot 的集成

概要云应用程序通常都需要使用前端网关&#xff0c;为用户、设备或其他应用程序提供同一个入口点。 在 Service Fabric 中&#xff0c;网关可以是任意无状态服务&#xff08;如 ASP.NET Core 应用程序&#xff09; 。本文介绍了如何将Ocelot用作 Service Fabric 应用程序的网关…

图论复习——最短路

知识点 最短路径算法 最短路径树 每个点uuu的父亲为使uuu得到最短距离的前驱节点&#xff0c;若有多个&#xff0c;则取任意一个。 题目 CF449B Jzzhu and Cities Blog CF464E The Classic Problem Blog [XSY3888] 传送门 对每个点uuu&#xff0c;记d(u)d(u)d(u)表示uuu…

Loj#143-[模板]质数判定【Miller-Rabin】

正题 题目链接:https://loj.ac/p/143 题目大意 给出一个数ppp&#xff0c;让你判定是否为质数。 解题思路 Miller−RabinMiller-RabinMiller−Rabin是一种基于费马小定理和二次探测定理的具有较高正确性的高效质数判定算法。 首先讲一下两个定理 费马小定理&#xff1a;gcd(…

【LCT】Tree II(luogu 1501)

Tree II luogu 1501 题目大意 给出一棵树&#xff0c;让你进行若干操作&#xff0c;操作如下&#xff1a; 1.把两个点路径上的所有点权值加k 2.把两个点路径上的所有点权值乘k 3.把一条边断开&#xff0c;连上另一条边 4.查询两个点路径上的权值和 输入样例 3 2 1 2 2 3 *…

图论复习汇总

三元环计数&四元环计数 Blog dfs树,点双,边双,强连通分量 Blog bfs树 对一个图运行 bfs 算法&#xff0c;每个点uuu的父亲定义为第一次遍历uuu时的前驱结点&#xff0c;若无则为根。 非树边只存在在同一层的两个点和相邻层的点中。 hihoCoder1147 时空阵 题意&#x…

P4718-[模板]Pollard-Rho算法

正题 题目链接:https://www.luogu.com.cn/problem/P4718 题目大意 给出一个数nnn&#xff0c;如果它是质数则输出PrimePrimePrime&#xff0c;否则输出它的最大质因子。 解题思路 Pollard-Rho\text{Pollard-Rho}Pollard-Rho算法的前置知识是Miller-Rabin\text{Miller-Rabin}M…

T-Dongle-S3开发笔记——创建工程

创建Hello world工程 打开命令面板 方法1&#xff1a;查看->命令面板 方法2&#xff1a;按F1 选择ESP-IDF:展示示例项目 创建helloworld 选择串口 选择芯片 至此可以编译下载运行了 运行后打印的信息显示flash只有2M。但是板子上电flash是W25Q32 4MB的吗 16M-bit

hdu 1576 A/B

文章目录题目&#xff1a;题解&#xff1a;代码&#xff1a;hdu 1576题目&#xff1a; 要求(A/B)%9973&#xff0c;但由于A很大&#xff0c;我们只给出n(nA%9973)(我们给定的A必能被B整除&#xff0c;且gcd(B,9973) 1)。 Input 数据的第一行是一个T&#xff0c;表示有T组数据。…

ASP.NET Core 中断请求了解一下(翻译)

本文所讲方式仅适用于托管在Kestrel Server中的应用。如果托管在IIS和IIS Express上时&#xff0c;ASP.NET Core Module(ANCM)并不会告诉ASP.NET Core在客户端断开连接时中止请求。但可喜的是&#xff0c;ANCM预计在.NET Core 2.2中会完善这一机制。1. 引言假设有一个耗时的Act…

子数整数(luogu 1151)

子数整数 luogu 1151 题目大意 给出一个数k&#xff0c;让你在10000~30000中求出满足前三位&#xff0c;中间三位&#xff0c;后三位都可被k整除的数 输入样例 15输出样例 22555 25555 28555 30000数据范围 0<k<1000 解题思路 暴力枚举 代码 #include<cstd…

2021-10-22

扫描线&#xff1a; https://www.cnblogs.com/Parsnip/p/10887135.html https://blog.csdn.net/Emma2oo6/article/details/120584307 https://blog.csdn.net/weixin_30609331/article/details/96234492 LIS& LCS https://www.xuebuyuan.com/586419.html https://blog.csdn…

.net core实践系列之短信服务-架构优化

前言通过前面的几篇文章&#xff0c;讲解了一个短信服务的架构设计与实现。然而初始方案并非100%完美的&#xff0c;我们仍可以对该架构做一些优化与调整。同时我也希望通过这篇文章与大家分享一下&#xff0c;我的架构设计理念。源码地址&#xff1a;https://github.com/SkyCh…

Poj 1061 青蛙的约会

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 143491 Accepted: 33018 Description 文章目录题目&#xff1a;思路:代码:题目传送题目&#xff1a; 两只青蛙在网上相识了&#xff0c;它们聊得很开心&#xff0c;于是觉得很有必要见一面。它们很高兴地发现它们住…

P3649-[APIO2014]回文串【PAM】

正题 题目链接:https://www.luogu.com.cn/problem/P3649 题目大意 一个字符串&#xff0c;求最大的回文串长度出现次数 解题思路 构建出PAM\text{PAM}PAM然后统计一下每个节点作为后缀的次数&#xff0c;failfailfail树上上传一下信息就好了&#xff0c;时间复杂度O(n)O(n)O…

【数学】拉格朗日插值(luogu 4781/金牌导航 拉格朗日插值-1)

拉格朗日插值 luogu 4781 金牌导航 拉格朗日插值-1 题目大意 给出n个点&#xff0c;让你确定经过这n个点且不超过n-1次的方程&#xff0c;现在给出k&#xff0c;让你求出其函数值 样例#1 输入样例#1 3 100 1 4 2 9 3 16输出样例#1 10201样例#2 输入样例#2 3 100 1 1 …

游戏 (博弈论)

https://blog.csdn.net/Mys_C_K/article/details/91443390

.NET Core中Object Pool的简单使用

前言复用&#xff0c;是一个重要的话题&#xff0c;也是我们日常开发中经常遇到的&#xff0c;不可避免的问题。举个最为简单&#xff0c;大家最为熟悉的例子&#xff0c;数据库连接池&#xff0c;就是复用数据库连接。那么复用的意义在那里呢&#xff1f;简单来说就是减少不必…

数论 欧几里得与扩展欧几里得

欧几里得算法&#xff1a; 求a&#xff0c;b的最大公约数 gcd&#xff08;a,b&#xff09; gcd(b,a%b) ll gcd(ll a,ll b) {return b0?a:gcd(b,a%b); }扩展欧几里得算法&#xff1a; 如果a&#xff0c;b是整数&#xff0c;一定存在x和y使得axbygcd&#xff08;a&#xff0c…

P4173-残缺的字符串【FFT】

正题 题目链接:https://www.luogu.com.cn/problem/P4173 题目大意 给出两个字符串S,TS,TS,T&#xff0c;其中包含小写字母和一些???&#xff0c;???可以匹配任何字符。 求有多少个ppp使得T0∼∣t∣−1Sp∼p∣t∣−1T_{0\sim |t|-1}S_{p\sim p|t|-1}T0∼∣t∣−1​Sp∼…