A

link



循环加每一个数,加到哪个数不能加了输出前一个数,注意如果加到最后还能加,记得输出\(n\)。

点击查看代码
#include<bits/stdc++.h>

using namespace std;

int n,m;
int h[105],sum; signed main(){ cin >> n >> m;
for(int i = 1;i <= n;++ i)
cin >> h[i]; for(int i = 1;i <= n;++ i){
sum += h[i];
if(sum > m){
cout << i-1 << endl;
return 0;
}
} cout << n << endl; return 0; }

B

link



输入时顺便存一下有几个大写字母几个小写字母,判断输出即可。

点击查看代码
#include<bits/stdc++.h>

using namespace std;

char s[105];
int n;
int bl,sl; signed main(){ cin >> s+1;
n = strlen(s+1); for(int i = 1;i <= n;++ i){
if(s[i] >= 'A'&&s[i] <= 'Z') bl++;
else sl++;
} if(bl > sl){
for(int i = 1;i <= n;++ i){
if(s[i] >= 'a'&&s[i] <= 'z')
s[i] = s[i]-'a'+'A';
}
}
else{
for(int i = 1;i <= n;++ i){
if(s[i] >= 'A'&&s[i] <= 'Z')
s[i] = s[i]-'A'+'a';
}
} cout << s+1; return 0; }

C

link



对于\(3^k*3^k\)的方块,递归四周八个\(3^{k-1}*3^{k-1}\)的方块,最中间的循环赋值。

注意边界。

点击查看代码
#include<bits/stdc++.h>

using namespace std;

int n;
char s[750][750];
int th; void dfs(int k,int l,int r,int x,int y){
if(k == 0){
s[r][y] = '#';
return;
}
int lr = (r-l+1)/3;
int xy = (y-x+1)/3;
for(int i = lr+l;i <= lr*2+l-1;++ i){
for(int j = xy+x;j <= xy*2+x-1;++ j){
s[i][j] = '.';
}
}
dfs(k-1,l,l+lr-1,x,x+xy-1);
dfs(k-1,l,l+lr-1,x+xy,x+xy*2-1);
dfs(k-1,l,l+lr-1,x+xy*2,y);
dfs(k-1,l+lr,l+lr*2-1,x,x+xy-1);
dfs(k-1,l+lr,l+lr*2-1,x+xy*2,y);
dfs(k-1,l+lr*2,r,x,x+xy-1);
dfs(k-1,l+lr*2,r,x+xy,x+xy*2-1);
dfs(k-1,l+lr*2,r,x+xy*2,y);
} signed main(){ cin >> n; th = 1;
for(int i = 1;i <= n;++ i) th *= 3; dfs(n,1,th,1,th); for(int i = 1;i <= th;++ i){
for(int j = 1;j <= th;++ j)
cout << s[i][j];
cout << endl;
} return 0; }

D

link



设\(k\)为\(n\)的位数,那么要求的数就是\(n*1+n*10^k+n*10^{2k}+……+n*10^{(n-1)k}\),也就是\(n(1+10^k+10^{2k}+……+10^{(n-1)k})\)。

观察\(1+10^k+10^{2k}+……+10^{(n-1)k}\),我们可以发现,它是一个公比为\(10^k\)的等比数列

运用求和公式,\(n(1+10^k+10^{2k}+……+10^{(n-1)k}) = \frac{n(10^{nk}-1)}{10^k-1}\)。

求出这个数即可(除法要用逆元)。

简单介绍一下逆元:

在模数为质数的情况下,除以\(x\)等于乘以\(x^{p-2}\)(\(p\)为模数)。

点击查看代码
#include<bits/stdc++.h>

#define int __int128
#define md 998244353 using namespace std; int n; int read(){
int x = 0,y = 1;
char ch = getchar();
while(ch < '0'||ch > '9'){
if(ch == '-') y = -1;
ch = getchar();
}
while(ch >= '0'&&ch <= '9'){
x = x*10+ch-48;
ch = getchar();
}
return x*y;
} void print(int x){
if(x < 0){
cout << '-';
x = -x;
}
if(x > 9) print(x/10);
putchar(x%10+'0');
} int dig(int x){
int ans = 0;
while(x){
ans++;
x /= 10;
}
return ans;
} int pw(int a,int x){
if(x == 0) return 1;
int z = pw(a,x/2);
z *= z;
z %= md;
if(x%2) z *= a;
return z%md;
} int inv(int a,int b,int p){
int k = pw(b,p-2);
return a%md*k%md;
} signed main(){ n = read(); int k = dig(n); //(n10^nk-n)/(10^k-1) //第一个目标n10^nk-n int t = pw(10,n*k)*n%md-n;
t = (t%md+md)%md; //第二个目标10^k-1 int tt = pw(10,k)-1;
tt = (tt%md+md)%md; //第三个目标答案 print(inv(t,tt,md)); return 0; }

随机推荐

  1. Flask源码阅读

    上下文篇 整个Flask生命周期中都依赖LocalStack()栈?.而LocalStack()分为请求上下文_request_ctx_stack和应用上下文_app_ctx_stack. _requ ...

  2. kubernetes 二次开发-认证,鉴权(1)

    基于webhook的认证 授权过程 认证授权服务需要满足如下kubernetes的规范 kubernetes api-server组件发送 http post 请求 url:https://authn ...

  3. C#异步调用Process(),后台静默调用cmd控制台

    C#调用cmd控制台操作,网上有太多的教程了,但是大多数都是执行完一条指令,退出Process,下次执行指令,再次new Process(),(只为了接收到cmd指令的回复,不然会进程阻塞,程序至此不 ...

  4. 安装centos7模板机[lvm版]

    1. 安装centos 7模板机 准备好centos7的镜像 下载地址:http://mirrors.aliyun.com/centos/7/isos/x86_64/ 安装centos 自定义硬件: ...

  5. 引用数据类型string字符串 类型转换

    String 任何" "之间的值 包括空格 String类型的字面取值 String str1 = "你好" String str2 = "hello ...

  6. 你知道键盘是如何工作的吗?(xv6键盘驱动程序)

    键盘驱动程序 公众号:Rand_cs 键盘如何工作的前文曾经说过,当时是以 Linux 0.11 为基础讲的但不系统,本文以 xv6 的键盘驱动程序为例来系统地讲述键盘是如何工作的.关于驱动程序前文磁 ...

  7. Windows 预览体验计划显示空白

    Open PowerShell as Administator.In the elevated PowerShell window, copy and paste the following comm ...

  8. Java类加载和对象创建

    引言 Java代码需要被使用,必须要经过类加载器加载到内存中,然后对应的类才能够被创建使用,这文对类加载和对象创建和过程进行分析. 类加载 Java类通过懒加载的方式,经过了Loading.Linki ...

  9. 【读论文】LLaMA: Open and Efficient Foundation Language Models

    论文:LLaMA: Open and Efficient Foundation Language Models 模型代码:https://github.com/facebookresearch/lla ...

  10. VScode连接服务器不用每次都输入密码

    VScode连接服务器不用每次都输入密码. 用git或xcode的ssh keygen生成一组不带密码的 rsa2048 的公钥id_rsa_nopasswd.pub和私钥id_rsa_nopassw ...