1.27 — 模拟三

· · 个人记录

[CSP-J 2025] 座位

::::success[time:] 10~42分钟 ::::

假设现在排名是r,所在列就是y = (r + n - 1) / n

去掉前y - 1列的人,r -= (y - 1) * n

给了n不是正确密码,但可以上述一次操作得到的序列,为有多少种可能的正确密码
- [x] 完成题目意思
::::success[思路]
枚举所有可能的密码
```cpp
枚举所有可能的密码{
检查密码是否可以用一次操作,得到n种状态
如果可以,答案++;
}
```
1.如何枚举出所有可能的密码?
```cpp
int a[10];
for(a[1] = 0;a[1]<=9;a[1]++){
//嵌套五次,存到a[1]....a[5]中
}
```
2.chcek的逻辑

这次密码能否通过操作,得到n种状态

bool chcek(int x){
    int cnt = 0;
    for(int i=1;i<=5;i++){
        if(ans[i] != a[x][i]){
            cnt++;
            if(cnt == 2){
                if(ans[i - 1] == a[x][i - 1])return 0;
                else{
      int v = (ans[i] - a[x][i] + 10) %10;
     int v1 = (ans[i - 1] - a[x][i - 1] + 10) % 10;
                    if(v != v1)return 0;
                }
            }
        }
    }
    if(cnt >= 3 || cnt == 0)return 0;
    else return 1;
}

3.f的逻辑

f检查这次的密码是否得到一个状态,能否修改一位数字,或者修改两位相邻的数字,变得和n一样

bool f(int b[],int a[]){
    int cnt = 0;
    for(int i=1;i<=5;i++){
        if(a[i] != b[i]){
            cnt++;
            if(x == -1)x = i;
            else y = i;
        }
    }
    if(cnt == 0)return 0;
    if(cnt == 1)return 1;
    if(cnt > 2 or y - x > 1)return 0;
    int n1 = a[x],n2 = a[y];
    for(int i=1;i<=9;i++){
        n1 = (n1 + 1) % 10;
        n2 = (n2 + 1) % 10;
        if(n1 == b[x] && n2 == b[y])return 1;
    }
}

::::

T725736 [NOIP 2012 普及组] 寻宝

::::success[题目意思]

n \times m$的矩阵,每楼有$m$个房间,编号$0 \sim m - 1

每个房间两个东西,是否有楼梯,一个数字x

数字x for当前楼梯,数到第x个有楼梯的房间,从这里到上一楼去

每楼第一个到的房间,上面的数字加起来,就是最终的值
- [x] 完成题目意思
::::success[思路]
输入结构体二维数组后

x,y表示当前所在的位置,每楼,模拟数带楼梯的房间的过程,在数组上循环找够房间数,上楼。。

优化时间复杂度。

假设第i层楼的带楼梯的房间数q[i]个,要数的房间数k % q[i]
- [x] 完成思路
::::success[你们最爱看的Code:]
```cpp
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
struct P{
int lt,x;
};
int n,m;
P a[10005][105];
int q[N];
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j].lt>>a[i][j].x;
if(a[i][j].lt == 1)q[i]++;
}
}
int x = 0,y,res = 0;
cin>>y;
while(x < n){
int k = a[x][y].x;
res = (res + k) % 20123;
k %= q[x];
if(k == 0)k = q[x];
while(1){
if(a[x][y].lt == 1)k --;
if(k == 0)break;
y = (y + 1) % m;
}
x ++;
}
cout<<res;
return 0;
}


::::