上午
学习英语(了解四级考试的每个部分,百词斩100个单词,写了3部分高频词汇。。。)2h
下午和晚上刷题加学知识5.5h 写总结1.5h
知识:bfs结合队列使用,看了再解炸弹人,宝岛探险,代码明天补上。
刷了洛谷3个题,vj4个题,下面是其中的几个题
①P2404 自然数的拆分问题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
我直接摆出来了(oh,no),没用搜索写哈哈。
AC代码:
#include<stdio.h>
int n;
int main()
{
scanf("%d",&n);
if(n==1)printf("\n");
else if(n==2)printf("1+1\n");
else if(n==3)printf("1+1+1\n1+2\n");
else if(n==4)printf("1+1+1+1\n1+1+2\n1+3\n2+2\n");
else if(n==5)printf("1+1+1+1+1\n1+1+1+2\n1+1+3\n1+2+2\n1+4\n2+3\n");
else if(n==6)printf("1+1+1+1+1+1\n1+1+1+1+2\n1+1+1+3\n1+1+2+2\n1+1+4\n1+2+3\n1+5\n2+2+2\n2+4\n3+3\n");
else if(n==7)printf("1+1+1+1+1+1+1\n1+1+1+1+1+2\n1+1+1+1+3\n1+1+1+2+2\n1+1+1+4\n1+1+2+3\n1+1+5\n1+2+2+2\n1+2+4\n1+3+3\n1+6\n2+2+3\n2+5\n3+4\n");
else printf("1+1+1+1+1+1+1+1\n1+1+1+1+1+1+2\n1+1+1+1+1+3\n1+1+1+1+2+2\n1+1+1+1+4\n1+1+1+2+3\n1+1+1+5\n1+1+2+2+2\n1+1+2+4\n1+1+3+3\n1+1+6\n1+2+2+3\n1+2+5\n1+3+4\n1+7\n2+2+2+2\n2+2+4\n2+3+3\n2+6\n3+5\n4+4\n");
return 0;
}
②P1219 [USACO1.5]八皇后 Checker Challenge - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
思路:用深搜加回溯,先分别为行,列,主对角线,副对角线建立一个数组,为的就是在放皇后的时候进行标记,主要就是副对角线的关系(这我开始没看懂,看了一下题解才知道),标记完之后要记得取消标记。
注:对于第二行的那个皇后来说,它的右斜线上的点,(1,3),(3,5),(4,6),我们可以看出,它的y-x是个定值2,但是看第四行的皇后的右斜线上的点(5,2),它的y-x是个负定值,而数组是不能存在负数下标的,所以把右斜线的数平移n个单位,总数组关系没变,
AC代码:
#include<stdio.h>
int n,sum=0;
int book[1010],col[1010];//行 列
int a[1010],b[1010];//主对角线和副对角线
void dfs(int x)
{
if(x>n)
{
sum++;//满足条件,增加
if(sum<4)//输出前三个满足条件的
{
printf("%d",book[1]);
for(int i=2;i<=n;i++)
printf(" %d",book[i]);
printf("\n");
}
return;
}
for(int k=1;k<=n;k++)
{
//判断列,主对角线,副对角线都没有
if(col[k]==0&&a[x+k]==0&&b[x-k+n]==0)
{
book[x]=k;//放上去,第x行第k个
col[k]=1;a[x+k]=1;b[x-k+n]=1;//标记
dfs(x+1);//继续推
col[k]=0;a[x+k]=0;b[x-k+n]=0;//取消标记,回溯
}
}
return ;
}
int main()
{
scanf("%d",&n);
dfs(1);//从这开始
printf("%d",sum);
}
③
我直接用的c++里的队列函数和栈函数 ,很简单
AC代码:
#include<bits/stdc++.h>
#include<stack>
#include<iostream>
using namespace std;
int main()
{
stack<int> st;
int n,t,x;
cin>>n;
while(n--)
{
cin>>t;
if(t==1)
{
cin>>x;
st.push(x);
}
else if(t==2)
{
if(st.empty()==true)
cout<<"empty"<<endl;
else
{
cout<<st.top()<<endl;
st.pop();
}
}
}
}
#include<bits/stdc++.h>
#include<queue>
#include<iostream>
using namespace std;
int main()
{
queue<int> que;
int n,t,x;
cin>>n;
while(n--)
{
cin>>t;
if(t==1)
{
cin>>x;
que.push(x);
}
else if(t==2)
{
if(que.empty()==true)
cout<<"empty"<<endl;
else
{
cout<<que.front()<<endl;
que.pop();
}
}
}
}
总计:8h
明日计划:
学习四级英语:
刷题
啊呀!一天又结束了,爬了爬了,学习很快lo,加油坚持努力!✌✌✌