自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(122)
  • 收藏
  • 关注

原创 CUDA_VISIBLE_DEVICES和device_ids的区别

device_ids中的值要满足单调增,device_ids中包含的卡数不大于 os.environ[“CUDA_VISIBLE_DEVICES”]中包含的卡数即可。比如我要用显卡2和6,可如下设置:device_ids=[0,2],os.environ[“CUDA_VISIBLE_DEVICES”]=”6,0,2"。在一个地方看到的,顺便记录下。

2023-02-03 16:13:00 577 1

原创 java第一次作业

4.Application:package java的代码;public class test1 { public static void main(String args[]) { System.out.println("My first Java!"); }}Applet:package java的代码;import java.awt.*;import java.applet.*;public class test1 extends Applet{ public voi

2022-10-15 09:47:22 136

原创 第十次java作业

3、public class crate{ static String loadStream(InputStream in) throws IOException { StringBuffer buffer = new StringBuffer(); int n = 1,i=5; byte[] buf = new byte[n]; // 缓冲区,大小为1字节 while(i>0) { in.read(buf,0

2022-10-15 09:47:10 124

原创 327. 玉米田

添加链接描述状压DP。#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=15,INF=0x3f,mod=1e8;ll a[M],dp[M][1<<M];vector<int

2022-04-13 17:35:48 206

原创 479. 加分二叉树

添加链接描述区间dp#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=35,INF=0x3f;int a[M],dp[M][M],g[M][M];void dfs(int l,int r)

2022-04-13 11:14:04 734

原创 320. 能量项链

添加链接描述#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=200,INF=0x3f;int a[M],dp[M][M];int main(){ int n; cin&gt

2022-04-09 20:57:37 317

原创 323. 战略游戏

树形dp,一般都是从叶子节点开始,所以一般和dfs相结合,这道题很静但,dp[i][1]表示以i为根节点并且选择i时的最少需要的士兵数,dp[i][0]表示以i为根节点并且不选择i时的最少需要的士兵数。递推公式也比较好写, dp[u][0]+=所有子节点dp[v][1]; dp[u][1]+=所有子节点min(dp[v][0],dp[v][1]);添加链接描述#include<bits/stdc++.h>#define ll long long#define x first#defi

2022-04-06 20:24:18 3690

原创 125. 耍杂技的牛

Wi +Si 从小到大排序即为最优。贪心题很多都是按照某种形式排序,那么可以从排序入手,第i个节点和第i+1个节点交互,如果不会产生更坏的结果,那要满足什么条件,然后就按照这个条件排序,比如这题如果满足wi+1+si+1<si+wi,那么最大值不会变大,。添加链接描述#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdi

2022-04-06 19:23:43 186

原创 104. 货仓选址

一开始想的是算平均值,但正解是算中位数。添加链接描述#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=1e5+5,INF=0x3f;ll a[M];int main(){ in

2022-04-06 16:11:10 143

原创 802. 区间和

离散化,将增加和查询时的坐标离散化,映射到01234…等自然数,即他们的下标,然后在离散化后的坐标进行增加和查询操作,能将-1e9~1e9映射到0-1e5。添加链接描述#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;

2022-04-06 15:12:25 112

原创 91. 最短Hamilton路径

状压DP添加链接描述#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=21,N=1<<M,INF=0x3f;int a[M][M],dp[N][M];int main(){ int n; cin>>n;

2022-04-01 12:06:43 121

原创 AcWing 285. 没有上司的舞会

添加链接描述树形dp#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=6e3+2,N=3005;int happy[M],dp[M][2];bool st[M];vector<int>g[M];void dfs(int u){

2022-04-01 11:21:05 124

原创 860. 染色法判定二分图

添加链接描述#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=1e5+2,N=3005;vector<int>g[M];int color[M];bool st[M];bool flag=true;void dfs(int u,int c)

2022-03-29 11:32:03 146

原创 846. 树的重心

dfs搜一下添加链接描述#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=1e5+2,N=3005;vector<int>g[M];bool st[M];int ans=1e9,n;int dfs(int x){ st[x]=tr

2022-03-29 10:51:05 119

原创 891. Nim游戏

添加链接描述结论:a0^a1^....^an==0 先手必败否则先手必胜证明如下:1.0^0^0^....^0=0,最终态为0。a0^a1^....^an==x(不为0)则从x一定能转移到0,假设让ai变成ai^x,ai^x一定小于ai,则a0^a1^..^ai^x..^an==0。2.a0^a1^..^ai..^an==0则无论怎么取都转化为一个不为0的数。反证法,假设3.a0^a1^..^ai`..^an==0,a0^a1^..^ai..^an和a0^a1^..^ai`..^an进行异或操作

2022-03-28 17:28:10 3984

原创 890. 能被整除的数

添加链接描述通过位运算来枚举。要从1开始,从0开始意味着什么都不选,是错误的。#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn=3e4+5,INF=0x3f,mod=1e9+7;int p[20];int main(){ ll n,m; cin>>n>>m; for(int i=0;i<m;i++) cin

2022-03-28 15:13:19 369

原创 291. 蒙德里安的梦想

添加链接描述状态压缩dp注意不能预处理ST数组,因为n不同,合法状态就不同,比如n等于5时,10000合法,n等于6时010000就不合法,10000和010000是一个数,但是数组里这个位置的值随n的不同而不同。#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn=3e4+5,INF=0x3f,mod=1e9+7;ll dp[15][maxn];bool st[maxn];

2022-03-28 11:36:07 643

原创 900. 整数划分

添加链接描述完全背包问题,背包容量为n,dp[i][j]为前i个数恰好组成j的数量。做这道题时候,我在想恰好装满和不装满有什么区别。考虑背包问题,如果背包要求恰好装满,与之前的区别是初始化的时候,dp[0]=0,其余的都初始化为-INF,二维的话dp[0][0]为0,其余为-INF,意思是让其非法,0个物品0个空间正好装满,0个物品j个空间没装满,某一个状态只能从上一个合法状态转移过来,即不为-INF。#include<bits/stdc++.h>#define ll long long

2022-03-27 09:56:15 147

原创 282. 石子合并

添加链接描述区间dp,dp[i][j]为i到j最小代价,枚举区间长度。#include<bits/stdc++.h>using namespace std;const int maxn=302,INF=0x3f;int dp[maxn][maxn],a[maxn],s[maxn];int main(){ int n; cin>>n; memset(dp,INF,sizeof(dp)); for(int i=1;i<=n;i++)

2022-03-26 20:30:35 203

原创 899. 编辑距离

添加链接描述#include<bits/stdc++.h>using namespace std;const int maxn=1e3+5,INF=0x3f;int dp[15][15];char a[maxn][15], b[15];int check(char s[],int q){ memset(dp,INF,sizeof(dp)); for(int j=0;j<=strlen(b+1);j++) dp[0][j]=j; for(

2022-03-26 20:19:09 214

原创 AcWing 902. 最短编辑距离

添加链接描述#include<bits/stdc++.h>using namespace std;const int maxn=1e3+5,INF=0x3f;int dp[maxn][maxn];char a[maxn],b[maxn];int main(){ int n,m; cin>>n>>a+1>>m>>b+1; memset(dp,INF,sizeof(dp)); for(int i=0;i&.

2022-03-26 17:16:50 52

原创 常见的DP问题

acwing算法课数字三角形添加链接描述#include<bits/stdc++.h>using namespace std;const int maxn=505,INF=0x3f;int a[maxn][maxn],dp[maxn][maxn];int main(){ int n; cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) cin>

2022-03-23 17:47:03 147

原创 01背包、完全背包

01背包#include<bits/stdc++.h>using namespace std;const int N = 1e3+5;int dp[N],v[N],w[N];int main(){ int n,V; cin >> n>>V; for(int i=1;i<=n;i++) cin >> v[i]>>w[i]; for(int i=1;i<=n;i++) fo

2022-03-22 21:06:08 130

原创 202006-3 Markdown渲染器

60分#include<bits/stdc++.h>using namespace std;const int N=1e5+5,INF=1e9;int w,f,in;//0 空行 1 段落 2 项目列表vector<string>a;int flag[N];int check(string str){ for(int i=0;i<str.length();i++) if(str[i]!=' ') return 1;

2022-03-19 20:41:19 573

原创 202009-3 点亮数字人生

60分#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=1e4+2,N=3005;struct node{ string name; int output; vector<int>input;}a[N];int Q,m

2022-03-18 19:52:16 279

原创 202104-3 DHCP服务器

#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int M=1e5+2;int N,Tdef,Tmax,Tmin,n;string H;struct IP{ string occpy; int state;//0 未分配、1 待分配、2 占用、3 过

2022-03-18 10:38:28 232

原创 202109-3 脉冲神经网络

66分。。。可能得用链式前向星自己写的空间不够,看网上的用滚动数组超时了,用vector写的。#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int N=1024,M=2e3+2;struct node{ double a,b,c,d;}s[M];dou

2022-03-17 21:05:56 1115

原创 202109-2 非零段划分

山峰模型#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int N=5e5+5,M=1e4+2;int a[N],cnt[M];int main(){ int n; cin>>n; for(int i=1;i<=n;i++)

2022-03-16 17:57:50 144

原创 201712-3 Crontab

#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};unordered_map<string,int>res;struct Time{ int year,mo

2022-03-16 16:18:42 118

原创 201709-3 JSON查询

#include<bits/stdc++.h>#define ll long long#define x first#define y second#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;int n,m;string str;struct node{ int type;//1 string 2 obj string t; nod

2022-03-14 11:12:05 2174

原创 201803-4 棋局评估

最大最小搜素#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int inf=1e9;int a[3][3];bool check(int x){ for(int i=0;i<3;i++) { if(a[i][0]==x&

2022-03-12 16:36:47 107

原创 201712-4 行车路线

最短路的变形在更新节点最短路的时候,记录上一个节点连续走过小道的长度,然后根据当前道路分类讨论即可。#include<bits/stdc++.h>#define ll long long#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);using namespace std;const int N=1e5+5;int n,m,d[505],vis[505],last[505],INF=0x3f;stru

2022-03-11 10:24:19 79

原创 201703-3 Markdown

#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn=1e2+5,INF=0x3f;string line;vector<string> a,b,strs;int f=0;//1 段落 2 标题 3 无序列表void em(string &s){ int cur=0,cur1=0; while(cur1<s.length())

2022-03-11 08:53:06 103

原创 201612-4 压缩编码

区间DP,前缀编码想到哈夫曼树,但是题中有个条件,必须按照字典序进行排列,我们从1到n枚举边界s,边界s左侧的都小于s,边界右侧的都大于s,在边界的两侧做哈夫曼树,两个子问题不相关,dp问题,其实不太好想,咱们可以想就两个点的情况,左侧一定小于右侧,这样递推出来一定能得到字典序。#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e3+5,INF=1e9;int n,dp[N][N],s

2022-03-09 16:17:33 82

原创 201612-3 权限查询

#include<bits/stdc++.h>#define ll long longusing namespace std;int p,r,u,num,q,mx=-1,mxx;map<string,vector<string>>role,user;map<string,int>recond;int judge(string s,string s1){ auto it=s.find(":"),its=s1.find(":"); i

2022-03-09 14:25:30 64

原创 201609-4 交通规划

最短路问题,迪杰斯特拉,只不过判断最短距离时将等于情况也纳入进来,因为有可能到1号点的距离有好几个最小值,选择到上一个点距离最小的那个,因为前面的点都已经建好高铁了,从哪个点都可以到,选择距离最小的,开一个数组保存每一个点连接上一个点的最小距离,每次开头加上距离。#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn=1e5+6,mod=1e9+7,INF=0x7f;int ans,n,

2022-03-08 16:13:07 97

原创 201604-4 游戏

bfs,因为题目说了一定能到,并且不能原地等待,所以我们可以将危险的块也加进去,只不过时间改成危险的块结束的时间,危险的块一定能走的,如果某一个块被危险的块围起来了,此时不能走,与题意不符,只不过几个快来回走。队列改成优先队列即可。#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=105,M=1e5+5,INF=0x3f;int n,m,t,a[N][N],b[N][N],vis[N][

2022-03-07 16:42:43 3738

原创 201604-3 路径解析

1.遇到字符串题应该先预处理,而不是一边操作一边处理。2.可以用vector代替堆栈,会方便很多。3.函数直接返回vector#include<bits/stdc++.h>#define x first#define y second#define ll long longusing namespace std;const int N=15,M=1e5+5,INF=0x3f;int n;string s[N];queue<string>e;void check

2022-03-07 11:16:43 51

原创 201512-4 送货

欧拉回路问题。如果图G(有向图或者无向图)中所有边一次仅且一次行遍所有顶点的通路称作欧拉通路。如果图G中所有边一次仅且一次行遍所有顶点的回路称作欧拉回路。具有欧拉回路的图称为欧拉图(简称E图)。具有欧拉通路但不具有欧拉回路的图称为半欧拉图。无向图G存在欧拉通路的充要条件是:G为连通图,并且G仅有两个奇度结点(度数为奇数的顶点)或者无奇度结点。当G是仅有两个奇度结点的连通图时,G的欧拉通路必以此两个结点为端点。当G是无奇度结点的连通图时,G必有欧拉回路。G为欧拉图(存在欧拉回路)的充分必要条件

2022-03-05 18:55:16 123

原创 201512-3 画图

这道题主要是数组坐标系转化为数字坐标系,数组坐标系逆时针旋转90°即为数字坐标系,输出的话y坐标逆序输出,x坐标正序输出。然后就是一个dfs填充。#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn=105,INF=0x3f;int n,m,q,vis[maxn][maxn],dx[]={-1,0,1,0},dy[]={0,1,0,-1};char a[maxn][maxn];vo

2022-03-05 16:28:29 110

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除