8.8总结
JWM918
·
·
个人记录
8.8总结
得分情况与用时
| 题目名称 |
得分 |
用时(分钟) |
备注 |
| \text{poker} |
\color{Green}100 |
\color{Cyan}5 |
/ |
| \text{explore} |
\color{Green}100 |
\color{Green}10 |
/ |
| \text{sticks} |
\color{Green}100 |
\color{Green}10 |
/ |
| \text{chain} |
\color{Red}0 |
\color{Brown}60 |
骗了分,没写对 |
| 总计 |
300 |
85 |
/ |
题目总结
P11227 [CSP-J 2024] 扑克牌(\text{poker})
题目大意
给定n张扑克牌的编号(两位字符,第一位为\texttt{DCHS}中的某个字符,第二位为\texttt{A23456789TJQK}中的某个字符),求凑出一副完整的扑克(不含大小王)还需要补充多少张。
解题思路
40分思路:
**100分思路**:
输入后用`map`或`set`去重,答案就是$52-$`map`或`set`的长度(`size()`)。
### 正确代码
用`map`的写法:
```cpp line-numbers
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n;
string s;
map<string,int>ma;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("poker.in","r",stdin);
freopen("poker.out","w",stdout);
cin>>n;
while(n--){
cin>>s;
ma[s]++;//去重
}
cout<<52-ma.size()<<endl;
return 0;
}
```
用`set`的写法:
```cpp line-numbers
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n;
string s;
set<string>t;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("poker.in","r",stdin);
freopen("poker.out","w",stdout);
cin>>n;
while(n--){
cin>>s;
t.insert(s);//去重
}
cout<<52-t.size()<<endl;
return 0;
}
```
### 个人总结
颗↑\~秒↓\~!
## P11228 [CSP-J 2024] 地图探险($\text{explore}$)
### 题目大意
($T$组询问)有一个$n \times m$的网格,`.`代表空地,`x`代表障碍。有一个人在网格上的初始位置为$(x,y)$,方向为$d$($d=0,1,2,3$分别代表右、下、左、上)。当他前面一格是空地同时前面没有越界,就走到这一格上,否则向右转$90$度。求他在$k$次操作(包含前进、转向)后经过的点的个数(包含起点)。
### 解题思路
直接按照题目要求模拟即可。需要注意以下事项。
方向数组:
```cpp line-numbers
//方向:右、下、左、上
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
```
方向的变化:`d=(d+1)%4`
### 正确代码
```cpp line-numbers
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int t,n,m,k,x,y,d,ans;
bool st[6][1005][1005];
char ma[1005][1005];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("explore.in","r",stdin);
freopen("explore.out","w",stdout);
cin>>t;
for(int s=1;s<=t;s++){
ans=0;
cin>>n>>m>>k>>x>>y>>d;
st[s][x][y]=1;//经过起点
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>ma[i][j];
}
}
while(k--){//k次操作
int nx=x+dx[d];
int ny=y+dy[d];
if(nx>0&&nx<=n&&ny>0&&ny<=m&&ma[nx][ny]=='.'){
st[s][nx][ny]=1;//经过该点
x=nx,y=ny;//更新坐标
}
else d=(d+1)%4;//转向
}
//统计答案
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans+=(int)st[s][i][j];
}
}
cout<<ans<<endl;
}
return 0;
}
```
### 个人总结
依旧颗秒。
## P11229 [CSP-J 2024] 小木棍($\text{sticks}$)
### 题目大意
有$n$根小木棍,请用所有小木棍拼出一个正整数(拼法如下图),让这个数尽可能小。

### 解题思路
要让数字更小,需要优先让数字的位数更小。
统计出每个数字用小木棍拼出的数量:
|数字 |小木棍根数|
|:--------:|:---:|
|$\texttt{0}$|$6$ |
|$\texttt{1}$|$2$ |
|$\texttt{2}$|$5$ |
|$\texttt{3}$|$5$ |
|$\texttt{4}$|$4$ |
|$\texttt{5}$|$5$ |
|$\texttt{6}$|$6$ |
|$\texttt{7}$|$3$ |
|$\texttt{8}$|$7$ |
|$\texttt{9}$|$6$ |
要让位数更小,就要让拼出的数字的使用根数更多。显然我们要优先凑$\texttt{8}$,剩下的小木棍再分类讨论。
设$cnt= \displaystyle \lfloor \frac{n}{7} \rfloor$(凑出的$\texttt{8}$的个数),$r=n$ $\text{mod}$ $7$(剩下的小木棍根数)。若$cnt>0$,则考虑以下情况:
|$r$|$cnt$|凑数方法 |
|:-:|:---:|:--------:|
|$=0$|$>0$ |直接输出$cnt$个$\texttt{8}$|
|$=1$|$>0$ |用第一个$\texttt{8}$和一根凑$\texttt{10}$,后面$cnt-1$个$\texttt{8}$|
|$=2$|$>0$ |前面一个$\texttt{1}$,后面$cnt$个$\texttt{8}$|
|$=3$|$=1$ |用$\texttt{8}$和三根凑$\texttt{22}$|
|^ |$>1$ |用前两个$\texttt{8}$和三根凑$\texttt{200}$,后面$cnt-2$个$\texttt{8}$|
|$=4$|$>0$ |用第一个$\texttt{8}$和四根凑$\texttt{20}$,后面$cnt-1$个$\texttt{8}$|
|$=5$|$>0$ |前面一个$\texttt{2}$,后面$cnt$个$\texttt{8}$|
|$=6$|$>0$ |前面一个$\texttt{6}$,后面$cnt$个$\texttt{8}$|
若$cnt=0$,则按以下表格输出:
|$n$或$r$ |答案 |
|:--:|:--------:|
|$=1$|$-1$ |
|$=2$|$\texttt{1}$|
|$=3$|$\texttt{7}$|
|$=4$|$\texttt{4}$|
|$=5$|$\texttt{2}$|
|$=6$|$\texttt{6}$|
### 正确代码
```cpp line-numbers
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int t,n;
int sticks[15]={-1,-1,1,7,4,2,6};//没有8时的输出
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("sticks.in","r",stdin);
freopen("sticks.out","w",stdout);
cin>>t;
while(t--){
cin>>n;
int cnt=n/7,r=n%7;
//有8
if(cnt>0){
if(r==0){
for(int i=1;i<=cnt;i++)cout<<8;
cout<<endl;
}
else if(r==1){
cout<<10;
for(int i=1;i<=cnt-1;i++)cout<<8;
cout<<endl;
}
else if(r==2){
cout<<1;
for(int i=1;i<=cnt;i++)cout<<8;
cout<<endl;
}
else if(r==3){
if(cnt>1){
cout<<200;
for(int i=1;i<=cnt-2;i++)cout<<8;
cout<<endl;
}
else cout<<22<<endl;
}
else if(r==4){
cout<<20;
for(int i=1;i<=cnt-1;i++)cout<<8;
cout<<endl;
}
else if(r==5){
cout<<2;
for(int i=1;i<=cnt;i++)cout<<8;
cout<<endl;
}
else if(r==6){
cout<<6;
for(int i=1;i<=cnt;i++)cout<<8;
cout<<endl;
}
}
//没有8
else cout<<sticks[r]<<endl;
}
return 0;
}
```
### 个人总结
肥肠《简单》,依旧颗秒。
## 整体总结
前$3$题直接颗秒。
$\text{T4}$本来要拿$5$分的,结果`break`的逻辑错了,可惜。
$\textsf{\textbf{By}}$ [$\textsf{\textbf{JWM918}}$](https://www.luogu.com.cn/user/1268845)