暴力遍歷,1-2020
的數位,然後判斷每一位,計數。
/*
* @Date: 2020-10-17 21:49:55
* @LastEditTime: 2020-10-17 21:58:58
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
for (int i = 1; i <= 2020; i++) {
int j = i;
while (j) {
if (j % 10 == 2){
ans++;
}
j /= 10;
}
}
cout << ans << endl;
return 0;
}
624
遍歷1-2020
之間的任意點對,判斷gcd
是否為1
,計數。
/*
* @Date: 2020-10-17 22:02:12
* @LastEditTime: 2020-10-17 22:02:24
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
for (int i = 1; i <= 2020; i++) {
for (int j = 1; j <= 2020; j++) {
if (__gcd(i, j) == 1){
ans++;
}
}
}
cout << ans << endl;
return 0;
}
2481215
模擬整個過程,判斷一下奇偶位置的特殊情況。
/*
* @Date: 2020-10-17 22:05:26
* @LastEditTime: 2020-10-17 22:06:55
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
int mmp[50][50], id;
int main() {
for (int i = 1; i <= 40; i++) {
if (i & 1) {
int idx = i, idy = 1;
for (int j = 0; j < i; j++){
mmp[idx - j][idy + j] = ++id;
}
} else {
int idx = 1, idy = i;
for (int j = 0; j < i; j++){
mmp[idx + j][idy - j] = ++id;
}
}
}
cout << mmp[20][20] << endl;
return 0;
}
761
直接模擬日期加法,遞增到2020年10月1日為止,計數(注意第一天也是2哦),注意判斷閏年,處理好年月日。
/*
* @Date: 2020-10-17 22:09:57
* @LastEditTime: 2020-10-17 22:11:55
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
int M[13] = {0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
int y = 2000, m = 1, d = 1, w = 6, ans = 2;
while (y != 2020 || m != 10 || d != 1) {
if (y % 400 == 0 || (y % 4 == 0 && y % 100)) {
M[2] = 29;
} else {
M[2] = 28;
}
d++;
w = (w + 1) % 7;
if (d > M[m]) {
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
}
if (d == 1 || w == 1) {
ans++;
}
ans++;
}
cout << ans << endl;
return 0;
}
8879
暴力列舉
2
7
=
128
2^7=128
27=128次方的所有七段碼,然後DFS
判斷聯通塊。(不愧是暴力杯 )
/*
* @Date: 2020-10-17 21:20:30
* @LastEditTime: 2020-10-17 22:15:57
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
freopen("in.txt", "w", stdout);
for (int a = 0; a <= 1; a++) {
for (int b = 0; b <= 1; b++) {
for (int c = 0; c <= 1; c++) {
for (int d = 0; d <= 1; d++) {
for (int e = 0; e <= 1; e++) {
for (int f = 0; f <= 1; f++) {
for (int g = 0; g <= 1; g++) {
int mmp[6][4] = {0};
if (a) {
for (int i = 1; i <= 3; i++) {
mmp[1][i] = 1;
}
}
if (b) {
for (int i = 1; i <= 3; i++) {
mmp[i][3] = 1;
}
}
if (c) {
for (int i = 3; i <= 5; i++) {
mmp[i][3] = 1;
}
}
if (d) {
for (int i = 1; i <= 3; i++) {
mmp[5][i] = 1;
}
}
if (e) {
for (int i = 3; i <= 5; i++) {
mmp[i][1] = 1;
}
}
if (f) {
for (int i = 1; i <= 3; i++) {
mmp[i][1] = 1;
}
}
if (g) {
for (int i = 1; i <= 3; i++) {
mmp[3][i] = 1;
}
}
printf("5 3\n");
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 3; j++) {
printf("%d", mmp[i][j]);
}
puts("");
}
puts("");
}
}
}
}
}
}
}
return 0;
}
/*
* @Date: 2020-10-17 21:20:03
* @LastEditTime: 2020-10-17 21:27:00
* @Author's blog: nuoyanli
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
char a[N][N];
int n, m, vis[N][N];
void dfs(int r, int c, int f) {
if (r < 0 || r >= m || c < 0 || c >= n) {
return;
}
if (vis[r][c] > 0 || a[r][c] != '1') {
return;
}
vis[r][c] = f;
for (int i = -1; i <= 1; i++){
for (int j = -1; j <= 1; j++){
if (i != 0 || j != 0){
dfs(r + i, c + j, f);
}
}
}
}
int main() {
int sum = 0;
freopen("in.txt", "r", stdin);
while (~scanf("%d%d", &m, &n)) {
for (int i = 0; i < m; i++){
scanf("%s", a[i]);
}
memset(vis, 0, sizeof(vis));
int cnt = 0;
for (int i = 0; i < m; i++){
for (int j = 0; j < n; j++){
if (vis[i][j] == 0 && a[i][j] == '1'){
dfs(i, j, ++cnt);
}
}
}
if (cnt == 1){
sum += 1;
}
}
printf("%d\n", sum);
return 0;
}
直接計算,然後注意四捨五入。
/*
* @Date: 2020-10-17 22:18:36
* @LastEditTime: 2020-10-17 22:21:48
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, jg = 0, yx = 0;
scanf("%d", &n);
while (n--) {
int x;
scanf("%d", &x);
if (x >= 60) {
jg++;
}
if (x >= 85) {
yx++;
}
}
double Jg = jg * 1.0 / n * 1.0;
double Yx = yx * 1.0 / n * 1.0;
int ans_jg = int(Jg * 1000 + 5) / 10;
int ans_yx = int(Yx * 1000 + 5) / 10;
printf("%d%%\n%d%%\n", ans_jg, ans_yx);
return 0;
}
算單字母的貢獻,然後記錄一下上一個位置。
/*
* @Date: 2020-10-18 13:13:49
* @LastEditTime: 2020-10-18 15:26:45
* @Author's blog: blog.nuoyanli.com
* @Description: Plum blossom from the bchter cold!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
char s[N];
ll vis[40];
int main() {
scanf("%s", s + 1);
int n = strlen(s + 1);
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += (i - vis[s[i] - 'a']) * (n - i + 1);
vis[s[i] - 'a'] = i;
}
cout << ans << endl;
return 0;
}