ABC357
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;
}
随机推荐
- yapi-plugin-notifier 插件安装报react 16.9.0版本错误 解决
使用yapi 1.9.2版本. 将配置的json文件替换掉. 参考这个issues解决方案:https://github.com/YMFE/yapi/issues/2109
- 莫烦tensorflow学习记录 (2)激励函数Activation Function
https://mofanpy.com/tutorials/machine-learning/tensorflow/intro-activation-function/ 这里的 AF 就是指的激励函数 ...
- C# 关于图片转ICO的代码整理(无损,不需要第三方类库)
概述(Overview) 感觉网上文章整理的不全,我这边做个专栏,专门做这个事情吧,节省大家搜索.筛选.整理的时间精力.有用可以点个赞.引用本文章请注明出处,谢谢. (I feel that the ...
- nginx aio模块添加与配置
1. 升级目的 让现有服务平滑过渡到高版本,减少服务漏洞,提高服务性能 让其支持nginx最新特性 nginx threads模块 2. 获取nginx1.7.2版本 wget http://ngin ...
- 关于DateFormater
一.关于时间的解析 let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ssZ& ...
- MySQL学习笔记-多表查询(上)
多表查询(上) 一. 多表关系 在实际应用中,根据需求,设计的表结构之间存在联系,联系一般分为以下三种 一对多(多对一) 多对多 一对一 1. 一对多(多对一) 案例:部门与员工的关系,一个部门对应多 ...
- JavaSE的方法 (函数)
目录 Java中的方法(函数) 方法声明格式:(与函数类似) Java中的方法(函数) Java方法是一段可重复使用的代码块,用于执行特定的任务.方法可以接受输入参数并返回一个值.在Java中,方法由 ...
- LeetCode 673. Number of Longest Increasing Subsequence 最长递增子序列的个数 (C++/Java)
题目: Given an unsorted array of integers, find the number of longest increasing subsequence. Example ...
- Elasticsearch之Nested Query nestedQuery查询数组
es是通过符合条件的json记录找出来,本身并不是将数据中的记录filter过滤.es nestedQuery不是过滤的结果,是匹配的这条es记录,所以数组中的其他的记录也会查询出来1.方法1:可以在 ...
- Markdown常用语法详解
背景知识 什么是html html是一种网页标记语言.我们平常见到的那么好看的网页就是通过html语言来编写的. html语言举例: <h1>hello world</h1> ...