总结
\color{red}{\texttt{注:由于luogu.me的原因,若总结有代码错误请}}
\color{red}{\texttt{复制原文至markdown查看}}
总结链 | 他人查看用总结链
比赛
| 序号 | 分数 | 状态 |
|---|---|---|
| A | 100 | AC |
| B | 10 | UNAC |
| C | ^ | ^ |
| D | 20 | ^ |
::::::info[总结] :::::success[T1] ::::success[题目思路]
:::: ::::success[正确代码]
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
constexpr int N = 1e5+5,M = 5*N,K = 5000;
int n,m;
char c[K][K];
bool vis[K];
int ans;
void dfs(int u,int num){
if(num==m){//达到条件
ans++;
return ;
}
if(u==n+1) return ;//出界
for(int i = 1;i<=n;i++){
if(c[u][i]=='#'&&vis[i]==0){//达到条件
vis[i]=1;
dfs(u+1,num+1);//递归
vis[i]=0;//回溯
}
}
dfs(u+1,num);//递归
}
void solve(){
ans=0;
for(int i = 1;i<=n;i++){
vis[i]=0;
string s;//转换
cin >> s;
for(int j = 1;j<=n;j++){
c[i][j]=s[j-1];
}
}
dfs(1,0);//调用
cout << ans << endl;//输出
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
while(1){
cin >> n >> m;//输入
if(n==m&&n==-1) exit(0);//结束代码
solve();//调用
}
return 0;
}
| :::: |
|---|
| :::::warning[T2] |
| ::::warning[错误代码] |
| ```cpp |
| #include<bits/stdc++.h> |
| #define ll long long |
| #define endl '\n' |
| using namespace std; |
| constexpr int N = 1e5+5,M = 5*N,K = 5000; |
| int n,k; |
| double r; |
| int main(){ |
| ios::sync_with_stdio(0); |
| cin.tie(0);cout.tie(0); |
| cin >> n >> k >> r; |
| cout << 2; |
| return 0; |
| } |
| `````` |
| :::: |
| ::::info[解题思路] |
| :::info[题意分析] |
| $$ |
| 给定元素n,r,k和n个由3个元素组成的序列X,Y,R\ |
| 要求:模拟一个5\times{}5的正方形图\ |
| 在图中画出k个半径为r的圆\ |
| 并在图中画出n个圆,第i个圆在(X_i,Y_i),半径R_i\ |
| 求:k个圆能覆盖最多的圆数量 |
| $$ |
| ::: |
| :::success[题目思路] |
| $$ |
| 首先输入,然后创建结构体Node\ |
| 定义Node包含:\ |
| 2个整数x和y\ |
| 创建类型为Node的数组A和Q\ |
| 使用DFS_u\ |
| 定义DFS_u: |
| 如果u\ge{k+1}那么:\ |
| ans=ans与\sum^{k}{i=1}\sum^{n}{j=1}f(\sqrt{(A_i的x-X_j)^2+(A_i的y-Y_j)},j)\ |
| 定义f(x,y)为: |
| 如果F_x=0且x\le{}r+R_y\ |
| 那么f(x,y)=1且F_x=1,否则=0\ |
| 最后输出ans |
| $$ |
| ::: |
| :::: |
| :::success[正确代码] |
| ```cpp |
| #include<bits/stdc++.h> |
| #define ll long long |
| #define endl '\n' |
| using namespace std; |
| constexpr int N = 1e5+5,M = 5*N,K = 5000; |
| int n,k; |
| struct node{ |
| int x,y; |
| }q[K]; |
| node a[K]; |
| int x[N],y[N]; |
| double R[N],r; |
| int idx,ans; |
| bool vis[N]; |
| bool f[N]; |
| void dfs(int u){ |
| if(u==k+1){ |
| int sum = 0; |
| fill(f,f+idx,0); |
| for(int i = 1;i<=k;i++){ |
| for(int j = 1;j<=n;j++){ |
| double dis=sqrt((a[i].x-x[j])(a[i].x-x[j])+(a[i].y-y[j])(a[i].y-y[j]));//定义位置 |
| if(dis<=r+R[j]&&f[j]==0){//达到条件 |
| sum++; |
| f[j]=1; |
| } |
| } |
| } |
| ans=max(ans,sum);//取最大值 |
| return ; |
| } |
| for(int i = 1;i<=idx;i++){//选或不选 |
| if(vis[i]==0){ |
| vis[i]=1; |
| a[u]=q[i]; |
| dfs(u+1); |
| vis[i]=0; |
| } |
| } |
| } |
| int main(){ |
| ios::sync_with_stdio(0); |
| cin.tie(0);cout.tie(0); |
| cin >> n >> k >> r; |
| r*=1.0; |
| for(int i = 1;i<=n;i++){ |
| cin >> x[i] >> y[i] >> R[i]; |
| R[i]*=1.0; |
| } |
| for(int i = -5;i<=5;i++){ |
| for(int j = -5;j<=5;j++){ |
| q[++idx]={i,j}; |
| } |
| } |
| dfs(1);//调用 |
| cout << ans;//输出 |
| return 0; |
| } |
| `````` |
| ::: |
| ::::: |
| :::::warning[T3] |
| ::::warning[错误代码] |
| ```cpp |
| #include<bits/stdc++.h> |
| #define ll long long |
| #define endl '\n' |
| using namespace std; |
| constexpr int N = 1e5+5,M = 5*N,K = 5000; |
int main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cout << 3; return 0; }
::::
::::info[解题思路]
:::info[题意分析]
$$
给定n,求:\\
在一个5\times{}5的棋盘中下n个子,每个子颜色相同\\
求:最大化五子连珠的状态和
$$
:::
:::success[题目思路]
$$
使用选和不选模拟下棋,再使用循环判断是否达到条件存储入Vis_k\\
最后i从1\sim{}12枚举,如果Vis_i是True,那么ans+i\\
最后输出ans
$$
:::
::::
:::success[正确代码]
```cpp
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
constexpr int N = 1e5+5,M = 5*N,K = 5000;
int n;
bool vis[7][7];
bool f[N];
void check(){//查看数量
int k = 0;
for(int i = 1;i <= 5;i++){
if(vis[i][1]&&vis[i][2]&&vis[i][3]&&vis[i][4]&&vis[i][5]) k++;
if(vis[1][i]&&vis[2][i]&&vis[3][i]&&vis[4][i]&&vis[5][i]) k++;
}
if(vis[1][1]&&vis[2][2]&&vis[3][3]&&vis[4][4]&&vis[5][5]) k++;
if(vis[5][1]&&vis[4][2]&&vis[3][3]&&vis[2][4]&&vis[1][5]) k++;
f[k] = 1;//存储
}
void dfs(int x,int y,int u){//模拟落子
if(u==n){
check();
return ;
}
if(x==6){//达到边界
return ;
}
int nx = x,ny=y+1;
if(ny == 6){//位置
nx = x+1;
ny = 1;
}
vis[x][y] = 1;//下棋
dfs(nx, ny, u + 1);
vis[x][y] = 0;
dfs(nx, ny, u);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
dfs(1, 1, 0);
int ans = 0;
for(int i = 0;i <= 12;i++){
if(f[i]) ans += i;//叠加
}
cout << ans;//输出
return 0;
}
| ::: |
|---|
| :::::warning[T4] |
| ::::warning[错误代码] |
| ```cpp |
| #include<bits/stdc++.h> |
| #define ll long long |
| #define endl '\n' |
| using namespace std; |
| constexpr int N = 1e5+5,M = 5*N,K = 5000; |
| int n,m; |
| int main(){ |
| ios::sync_with_stdio(0); |
| cin.tie(0);cout.tie(0); |
| cin >> n >> m; |
| if(m==1){ |
| cout <<2; |
| }else if(m==2){ |
| cout << 2; |
| }else if(m==7){ |
| cout << 2122; |
| }else cout << 2; |
| return 0; |
| } |
| ```````` |
| :::: |
| ::::info[解题思路] |
| :::info[题意分析] |
| $$ |
| 给定一个n\times{}m的棋盘,可以在棋盘上落子\ |
| 求:所有落子方案中连通块大小全为奇数的数量和 |
| $$ |
| ::: |
| :::success[题目思路] |
| $$ |
| 使用2个DFS,一个用于判断连通块,一个用于赋值与标记\ |
| 最后统计即可 |
| $$ |
| ::: |
| :::: |
| :::success[正确代码] |
| ```cpp |
| #include<bits/stdc++.h> |
| #define ll long long |
| #define endl '\n' |
| using namespace std; |
| constexpr int N = 1e5+5,M = 5*N,K = 5000; |
| int n,m; |
| int ans; |
| bool vis[K][K]; |
| int a[K][K]; |
| int dx[4]={1,-1,0,0}; |
| int dy[4]={0,0,1,-1}; |
| int dfs_block(int x,int y,int color){//连通块 |
| int cnt = 1; |
| vis[x][y] = 1; |
| for(int i = 0;i<4;i++){ |
| int xx = x+dx[i], yy = y+dy[i]; |
| if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[xx][yy]==color&&!vis[xx][yy]){//条件 |
| cnt += dfs_block(xx,yy,color);//递归 |
| } |
| } |
| return cnt;//返回答案 |
| } |
| void dfs(int x,int y){//落子 |
| if(x>n){//边界 |
| for(int i = 1;i<=n;i++){//清空 |
| for(int j = 1;j<=m;j++){ |
| vis[i][j]=0; |
| } |
| }for(int i = 1;i<=n;i++){//连通块 |
| for(int j = 1;j<=m;j++){ |
| if(!vis[i][j]){ |
| int size = dfs_block(i,j,a[i][j]); |
| bool flag = 1; |
| for(int ii = 1;ii<=n;ii++){ |
| for(int jj = 1;jj<=m;jj++){ |
| if(vis[ii][jj] && a[ii][jj]==a[i][j]){ |
| for(int k=0;k<4;k++){ |
| int ni = ii+dx[k], nj = jj+dy[k]; |
| if(ni>=1 && ni<=n && nj>=1 && nj<=m){ |
| if(a[ni][nj]==a[i][j] && !vis[ni][nj]){ |
| flag = 0; |
| } |
| } |
| } |
| } |
| } |
| } |
| if(!flag){ |
| return; |
| } |
| if(size%2==0){ |
| return; |
| } |
| } |
| } |
| } |
| ans++;//增加 |
| return; |
| } |
| a[x][y]=0;//下棋 |
| if(y==m) dfs(x+1,1); |
| else dfs(x,y+1); |
| a[x][y]=1;//回溯 |
| if(y==m) dfs(x+1,1); |
| else dfs(x,y+1); |
| } |
| int main(){ |
| ios::sync_with_stdio(0); |
| cin.tie(0);cout.tie(0); |
| cin >> n >> m; |
| dfs(1,1);//调用 |
| cout << ans; |
| return 0; |
| } |
| ``````` |
| ::: |
| ::::: |
| :::::: |