P;
const int maxn=1e3+7;
bool vis[maxn][maxn];
int n,m;
char a[maxn][maxn];
int dx[4]={1,0,0,-1},dy[4]={0,-1,1,0};//DLRU
int path[maxn][maxn];//记录前驱
int ss[maxn][maxn];//记录到当前点的最短步数
char str[4]={'U','R','L','D'};
void dfs(int s,int x,int y){//回溯输出路径
if(x==0&&y==0)return;
if(s==0)dfs(path[x+1][y],x+1,y);
else if(s==1)dfs(path[x][y-1],x,y-1);
else if(s==2)dfs(path[x][y+1],x,y+1);
else if(s==3)dfs(path[x-1][y],x-1,y);
printf("%c",str[s]);
}
void bfs(){
queue q;
q.push(P(0,0));
vis[0][0]=1;
ss[0][0]=0;
while(!q.empty()){
P p=q.front();q.pop();
if(p.first==n-1&&p.second==m-1){
break;
}
for(int i=0;i<4;i++){
int nx=p.first+dx[i],ny=p.second+dy[i];
if(nx>=0&&nx=0&&ny>a[i];
}
bfs();
return 0;
}
```
#### Day.4
##### 问题 1427:买不到的数目
解题思路:数学规律题
```cpp
#include
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)cout<<(a*b-a-b)<
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
typedef pair P;
const int inf=0x3f3f3f3f;
const int maxn=1e3+7;
const int mod=123456789;
#define pb push_back
#define ft first
#define sd second
int t,n,m;
vector v;
void getp(int x){
v.clear();
for(int i=2;i*i<=x;i++){
v.pb(P(i,0));
while(x%i==0)x/=i,++v.back().sd;
if(!v.back().sd)v.pop_back();
}
if(x>1)v.pb(P(x,1));
}
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
getp(n);
if((v.size()==1&&v[0].sd==2)||(v.size()==2&&v[0].sd+v[1].sd==2))puts("Yes");
else puts("No");
}
return 0;
}
```
##### 问题 1932:第二大整数
解题思路:可以用set,也可以用优先级队列,也可以排序完之后找第二大值,做法很多。
```cpp
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
typedef pair P;
const int inf=0x3f3f3f3f;
const int maxn=1e3+7;
const int mod=123456789;
#define pb push_back
#define ft first
#define sd second
int t,n,m;
priority_queue pq;
int main()
{
while(!pq.empty())pq.pop();
while(~scanf("%d",&n)){
if(n==0)break;
pq.push(n);
}
pq.pop();
cout<
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
typedef pair P;
const int inf=0x3f3f3f3f;
const int maxn=1e3+7;
const int mod=123456789;
#define pb push_back
#define ft first
#define sd second
int t,n,m;
set s;
set::iterator it;
int main()
{
s.clear();
scanf("%d",&n);
for(int i=0;i
#include
#include
#include
#include
发表评论 取消回复