A门牌制作
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int LL;
int main()
{
LL ans = 0;
for (int i = 1; i <= 2020; i ++)
{
int x = i;
while (x)
{
if (x % 10 == 2) ans ++;
x /= 10;
}
}
cout << ans << endl;
return 0;
}
B既约分数
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int LL;
int gcd(int a, int b)
{
return b? gcd(b, a % b) : a;
}
int main()
{
LL sum = 0;
for (int i = 1; i <= 2020; i ++)
{
for (int j = 1; j <= 2020; j ++)
{
if (gcd(i, j) == 1) sum ++;
}
}
cout << sum << endl;
return 0;
}
C蛇形填数
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int LL;
int main()
{
int n = 20;
n = n * 2 - 1;
LL sum = 0;
for (int i = 1; i <= n; i ++)
{
sum += i;
}
for (int i = 1; i <= 20 - 1; i ++) sum --;
cout << sum << endl;
return 0;
}
D七段码
E跑步锻炼
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int LL;
int motch[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int run(int year)
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return 1;
return 0;
}
int main()
{
LL day = 0, mot = 0, ans = 0;
for (int i = 2000; i <= 2020; i ++) // 年
{
if (run(i)) motch[2] = 29;
else motch[2] = 28;
for (int j = 1; j <= 12; j ++) // 月份
{
if (i == 2020 && j == 10)
{
ans += 2;
break;
}
for (int k = 1; k <= motch[j]; k ++) // 天数;
{
day ++;
if (k != 1)
{
if (day % 7 == 3) ans += 2;
else ans ++;
}else ans += 2;
}
// cout << ans << endl;
}
}
cout << ans << endl;
return 0;
}
F回文日期
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int date)
{
int year = date / 10000;
int month = date % 10000 / 100;
int day = date % 100;
if(!day || month < 0 || month > 12 ) return 0;
if(month != 2 && day >months[month]) return 0;
if(month == 2)
{
if((year%4==0&&year%100!=0)||(year%400==0)) if(day > 29) return false;
else if(day > 28) return 0;
}
return 1;
}
bool check1(string s)
{
int len = s.size();
for(int i = 0, j = len - 1; i < j ; i++,j--)
{
if(s[i] != s[j]) return 0;
}
return 1;
}
bool check2(string s)
{
if(check1(s))
{
if(s[0]!=s[2] || s[1]!= s[3] || s[0] == s[1]) return false;
return true;
}
}
void solve()
{
int date,flag=0;
cin>>date;
for(int i = date + 1; ;i++)
{
if(check(i))
{
stringstream ss;
ss << i;
string s = ss.str();
if(check1(s)&&!flag)
{
cout<<i<<endl;
flag = 1;
}
if(check2(s))
{
cout<<i<<endl;
return ;
}
}
}
}
int main()
{
int t;
cin >> t;
while (t -- )
{
solve();
}
return 0;
}
G成绩统计
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define int long long
using namespace std;
signed main()
{
double sum1 = 0.0, sum2 = 0.0, n;
cin >> n;
for (int i = 1; i <= n; i ++)
{
int x;
cin >> x;
if (x >= 85) sum1 ++;
if (x >= 60) sum2 ++;
}
int x = (sum2 * 100.0)/n + 0.5;
int y = (sum1 * 100.0)/n + 0.5;
cout << x << "%" << endl << y << "%" << endl;
return 0;
}
H字串分值求和
思路:
计算方式为:( i - 上一个‘a’字符出现的位置 )乘( 字符串总长度 - i );
若‘a’为首次出现,则计算方式为( i + 1 )乘( 字符串总长度 - i );
列为:
a
ab
aba
abab
ababc
5个,权值应为5;
算式:(0+1)*(5-0)=5
代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#define int long long
using namespace std;
int num[27];
signed main()
{
string s;
cin >> s;
int len = s.size();
memset(num, -1, sizeof num);
int ans = 0;
for (int i = 0; i < s.size(); i ++)
{
ans += (int)(i - num[s[i] - 'a']) * (len - i);
num[s[i] - 'a'] = i;
}
cout << ans << endl;
return 0;
}
I平面切分
思路:
首先每一条不重复的线ans至少加一,该条线与之前有一个交点就再加一。
代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define int long long
using namespace std;
set<pair<double, double> > s;
void solve()
{
int ans = 1;
int n;
cin >> n;
for (int i = 1; i <= n; i ++)
{
int x, y;
cin >> x >> y;
if (s.count({x, y})) continue;
ans ++;
s.insert({x, y});
set<pair<double, double> > p;
for (auto [xx, yy]:s)
{
if (x == xx) continue;
double dx = (yy - y)/(x - xx);
double dy = x * dx + y;
p.insert({dx, dy});
}
ans += p.size();
}
cout << ans;
}
signed main()
{
solve();
return 0;
}