小蓝每天都锻炼身体。正常情况下,小蓝每天跑1千米。如果某天是周一或者月初(1日),为了激励自己,小蓝要跑2千米。如果同时是周一或月初,小蓝也是跑2千米。小蓝跑步已经坚持了很长时间,从2000年1月1日周六(含)到2020年10月1日周四(含)。请问这段时间小蓝总共跑步多少千米?
题目解析:从一月一日开始,如果是闰年就要让二月变成29天,然后计数的时候对周一和每月一号进行特判,然后到截止日期就停止,并且返回输出的数字。
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 1e5+10;
void solve(){
int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int year,month,day; int cnt = 0;
int ans = 6;
for(year=2000;year<=2020;year++){
if(year%400==0||(year%4==0&&year%100!=0)){
months[2] = 29;
}
else months[2] = 28;
for(month=1;month<=12;month++){
for(day=1;day<=months[month];day++){
cnt++;
if(ans>7) ans=1;
if(ans==1||day==1){
cnt++;
}
ans++;
if(year==2020&&month==10&&day==1){
cout<<cnt;
return;
}
}
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
}
|
货物摆放
题目:题目描述
小蓝有一个超大的仓库,可以摆放很多货物。
现在,小蓝有n箱货物要摆放在仓库,每箱货物都是规则的正方体。小蓝规定了长、宽、高
三个互相垂直的方向,每箱货物的边都必须严格平行于长、宽、高。
小蓝希望所有的货物最终摆成一个大的长方体。即在长、宽、高的方向上分别堆L、W、
H的货物,满足n=LxWxH。
给定n,请问有多少种堆放货物的方案满足要求。
例如,当n=4时,有以下6种方案:1×1×4、1×2×2、1×4×1、2×1x
2、2×2×1、4×1×1.
请问,当n=2021041820210418 (注意有16位数字)时,总共有多少种方案?
提示:建议使用计算机编程解决问题。
问题解析:
如果纯暴力会t,就是一个先找到约数,找到约数然后对约数进行三重循环然后找到能够能够对应的就情况数加1,约数的找就是从小开始,只要找到小的约数,然后在找相乘的另外一个大的约数即可。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 1e7+10;
long long n = 2021041820210418;
long long arr[N];
void solve(){
ll ans = 0;
ll i = 0;
ll cnt = 0;
for(ll i = 1;i*i<=n;i++){
if(n%i==0){
arr[cnt] = i;
cnt++;
if(n/i!=i){
arr[cnt] = n/i;
cnt++;
}
} }
for(ll a = 0;a<cnt;a++){ for(ll b = 0;b<cnt;b++){
for(ll c = 0;c<cnt;c++){
if(arr[a]*arr[b]*arr[c]==n){
ans++;
}
}
}
}
cout<<ans;
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
}
|
特别数的和
题目:题目描述
小明对数位中含有2、0、1、9的数字很感兴趣(不包括前导0),在1到40中这样的
数包括1、2、9、10至32、39和40,共28个,他们的和是574。
请问,在1到n中,所有这样的数的和是多少?
输入描述
输入格式:
输入一行包含两个整数n(1≤n≤104)。
输出描述
输出一行,包含一个整数,表示满足条件的数的和。
题目解析:只需要找到对每个数的每一位数进行取模运算,然后看每一位数是不是符合上面题目的条件。有就计数器加1
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 1e5+10;
bool check(int n){
while(n){
int s = n%10;
n/=10;
if(s==1||s==2||s==9||s==0){
return true;
}
}
return false;
}
void solve(){
int num;
cin>>num;
int ans = 0;
for(int i = 1;i<=num;i++){
if(check(i)) ans+=i;
}
cout<<ans;
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
}
|
天干地支
题目描述:古代中国使用天干地支来记录当前的年份。
天干一共有十个,分别为:甲(jia)、乙(yi)、丙(bing)、丁(ding)、戊(wù)、
己(ji)、庚(gēng)、辛(xin)、壬(rén)、癸(gui)。
地支一共有十二个,分别为:子(zi)、丑(chou)、寅(yin)、卯(mao)、辰
(chén)、巳(si)、午(wu)、未(wèi)、申(shen)、酉(yǒu)、戌(xū)、亥
(hài) .
将天干和地支连起来,就组成了一个天干地支的年份,例如:甲子。
2020年是庚子年。
每过一年,天干和地支都会移动到下一个。例如2021年是辛丑年。
每过60年,天干会循环6轮,地支会循环5轮,所以天干地支纪年每60年轮回一次。
例如1900年,1960年,2020年都是庚子年。
给定一个公元纪年的年份,请输出这一年的天干地支年份。
解析:2020年模10,就可以知道天干的顺序是从庚开始的,然后模12就可以知道4是子,然后往下就是从0-11的顺序了,所以我们可以手动打表将这些东西排序好。
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 1e5+10;
void solve(){
int year;
std::cin >> year;
std::string heavenly[10] = {"geng", "xin", "ren", "gui", "jia", "yi" , "bing", "ding", "wu", "ji"};
std::string earthlyBranch[12] = {"shen", "you", "xu", "hai", "zi", "chou", "yin", "mou", "chen", "si", "wu", "wei"};
std::cout << heavenly[year % 10] << earthlyBranch[year % 12] << std::endl;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
}
|
模拟章节就结束,难度不大