2026.3.14习题总结
huanzhenyang0420 · · 个人记录
P1146 硬币翻转
题目描述
在桌面上有一排硬币,共
数据范围:N 为不大于 100 的偶数
思路
经过多组数据可以得出,最少的次数是 n 次。接着我们可以发现第 i-1 行的第 j 个和第 i 行的第 j 个是相同的。
这是因为题目说:
对于有多种操作方案的情况,则只需操作的字典序最小输出一种。
正确代码:
#include<bits/stdc++.h>
#include<math.h>
#include<cmath>
using namespace std;
typedef long long ll;
bool vis[105];
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
cout<<n<<'\n';
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(j!=i) vis[j]=(!vis[j]);
cout<<vis[j];
}
cout<<'\n';
}
return 0;
}
/*
4
4
0111
1100
0001
1111
*/
//大:localStorage.cp6_player_id='1f88476d-6223-4bd3-b3c9-199ca12066e0'
//小:localStorage.cp6_player_id='60bb16e0-3c7c-4351-af7f-7549a250d4c6'
P1611 循环的数字
题目描述
两个不同的正整数
现在给定正整数
数据范围:1\le A,B \leq 2\times 10^6 。
思路:
这一题没有什么太复杂的思路
重要部分:
for(int i=a;i<b;i++){
n=i;
m=(n%10)*num[cnt-1]+n/10;
while(n!=m){
ans+=n<m&&m<=b;
m=(m%10)*num[cnt-1]+m/10;
}
}
正确代码:
#include<bits/stdc++.h>
#include<math.h>
#include<cmath>
using namespace std;
typedef long long ll;
int num[10]={1,10,100,1000,10000,100000,1000000};
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a,b,n,m,cnt=0,pre,ans=0;
cin>>a>>b;
pre=a;
while(pre){
pre/=10;
cnt++;
}
for(int i=a;i<b;i++){
n=i;
m=(n%10)*num[cnt-1]+n/10;
while(n!=m){
ans+=n<m&&m<=b;
m=(m%10)*num[cnt-1]+m/10;
}
}
cout<<ans;
return 0;
}
/*
*/
//大:localStorage.cp6_player_id='1f88476d-6223-4bd3-b3c9-199ca12066e0'
//小:localStorage.cp6_player_id='60bb16e0-3c7c-4351-af7f-7549a250d4c6'