1.27 — 模拟三
[CSP-J 2025] 座位
::::success[
- [x] 完成
time ::::success[题目意思] 算出第一个人的排名,按照下图去算出他在第几行第几列。 :::: - [x] 完成题目意思
::::success[思路]
数学
想办法算出小
R 会在第y列,把前y - 1列的人去掉,剩下的数字,就是在第y列的第几行
假设现在排名是r,所在列就是y = (r + n - 1) / n
去掉前y - 1列的人,r -= (y - 1) * n
-
如果
y不是偶数,r就是我所在的行了 -
如果 y是偶数,n - r + 1就是我所在的行了 -
[x] 完成思路 ::::success[你们最爱看的Code:]
#include<bits/stdc++.h> using namespace std; const int N = 106 + 10; int n,m,a[N],k = 1; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>m; for(int i=1;i<=n*m;i++){ cin>>a[i]; } for(int i=2;i<=n*m;i++){ if(a[i] > a[1]){ k++; } } int c = (k-1)/n+1,r; if(c%2){ r = k%n?k%n:n; } else r = n - (k%n?k%n:n)+1; cout<<c<<" "<<r; return 0; }:::: ::::success[难度] 彳亍 ::::
T725735 [CSP-S 2023] 密码锁
::::success[错因:]
-
:::: -
[x] 完成错因 ::::success[
time :] 20~40分钟 :::: -
[x] 完成
time ::::success[题目意思] 有五个数字,改变其中一个数字或者改变其中两位相邻的数字。
| 给了 |
|---|
| - [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;
}
}
::::
- [x] 完成思路
::::success[你们最爱看的Code:]
#include<bits/stdc++.h> using namespace std; int n,m,ans[10],a[10][7],cnt; 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; } void dfs(int step){ if(step > 5){ for(int i=1;i<=n;i++){ if(chcek(i) == 0)return; } cnt++; return; } for(int i=0;i<=9;i++){ ans[step] = i; dfs(step + 1); } } int main(){ cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=5;j++){ cin>>a[i][j]; } } dfs(1); cout<<cnt; return 0; }::::
T725736 [NOIP 2012 普及组] 寻宝
::::success[题目意思]
每个房间两个东西,是否有楼梯,一个数字
数字
| 每楼第一个到的房间,上面的数字加起来,就是最终的值 |
|---|
| - [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; |
| } |
::::