题意:
做法:直接计算。
代码:
#include<bits/stdc++.h>
using namespace std;
int ct2(int i) {
int cnt = 0;
while(i) {
if(i%10 == 2) ++cnt;
i /= 10;
}
return cnt;
}
int main() {
int sum = 0;
for(int i = 1; i <= 2020; ++i) {
sum += ct2(i);
}
cout << sum;
return 0;
}
答案:624
题意:
做法:直接暴力找。
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
for(int i = 1; i <= 2020; ++i) {
for(int j = 1; j <= 2020; ++j) {
if(__gcd(i, j) == 1) ++cnt;
}
}
cout << cnt;
return 0;
}
答案:2481215
题意:
做法:暴力打出来。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int tu[N][N];
int main() {
int x = 0, y = 1, cnt = 0;
for(int i = 1; i <= 60; ++i) {
if(i&1) ++x;
else ++y;
tu[x][y] = ++cnt;
for(int j = 0; j < i-1; ++j) {
if(i & 1) {
tu[x-1][y+1] = ++cnt;
--x; ++y;
} else {
tu[x+1][y-1] = ++cnt;
++x; --y;
}
}
}
for(int i = 1; i <= 20; ++i) {
for(int j = 1; j <= 20; ++j) {
cout << tu[i][j] << " ";
}
cout << "\n";
}
cout << tu[20][20];
return 0;
}
答案:761
题意:
做法:一天一天模拟,细节比较多。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
int res = 0;
int y = 1999, m = 12, d = 31, w = 4;
while(1) {
++d; w = (w + 1) % 7;
if(d > mon[m]) {
++m; d = 1;
if(m > 12) {
++y; m = 1;
if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) mon[2] = 29; //闰年
else mon[2] = 28;
}
}
if(d == 1 || w == 0) ++res;
++res;
//cout << y << " " << m << " " << d << " " << w << " " << res << "\n";
if(y == 2020 && m == 10 && d == 1) break;
}
cout << res;
return 0;
}
答案:8879
题意:
做法:二进制枚举再判断选到的点是否连通(用dfs判断)。
代码:
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
int f = 1; res = 0;
char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int a[10] = {0, 1, 2, 3, 4, 5, 6, 7};
int tu[N][N];
void init() {
tu[0][0] = tu[0][1] = tu[0][2] = tu[0][3] = tu[0][4] = tu[0][5] = tu[0][6] = tu[0][7] = 1;
tu[1][2] = tu[1][3] = 1;
tu[2][1] = tu[2][4] = tu[2][5] = 1;
tu[3][1] = tu[3][4] = tu[3][6] = 1;
tu[4][2] = tu[4][3] = tu[4][5] = tu[4][6] = 1;
tu[5][2] = tu[5][4] = tu[5][7] = 1;
tu[6][3] = tu[6][4] = tu[6][7] = 1;
tu[7][5] = tu[7][6] = 1;
}
int ans;
int fa[N];
void dfs(int u) {
fa[u] = 0;
for(int i = 1; i <= 7; ++i) {
if(tu[u][i] && fa[i]) dfs(i);
}
}
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
void solve (int x) {
int f = 1;
for(int i = 0; i < 7; ++i)
if((x>>i)&1) fa[i+1] = 1;
for(int i = 1; i <= 7; ++i) {
if(fa[i]) {
dfs(i); break;
}
}
for(int i = 1; i <= 7; ++i) {
if(fa[i]) f = 0;
fa[i] = 0;
}
ans += f;
}
int main() {
init();
for(int i = 1; i < (1 << 7); ++i) solve(i);
cout << ans;
return 0;
}
答案:80
题意:点此进入
统计成绩的及格率和优秀率。
做法:直接贪心即可。
代码:
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
int f = 1; res = 0;
char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int main() {
int n; scanf("%d", &n);
double jg = 0, yx = 0, x;
_rep(1, n, i) {
scanf("%lf", &x);
if(x >= 85) ++yx;
if(x >= 60) ++jg;
}
printf("%.0lf%\n%.0lf%\n", jg*100/n, yx*100/n);
return 0;
}
题意:点此进入
计算出下一个回文型日期和ABABBABA日期。
做法:直接暴力判断就好了,需要注意的点是A!=B。
代码:
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
int f = 1; res = 0;
char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int mon[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool ishw(string s) {
int l = 0, r = s.size()-1;
while(l < r) {
if(s[l] != s[r]) return false;
++l; --r;
}
return true;
}
bool isAB(string s) {
if(s[0] == s[2] && s[0] == s[5] && s[5] == s[7])
if(s[1] == s[3] && s[3] == s[4] && s[4] == s[6])
if(s[0] != s[1]) return true;
return false;
}
int main() {
int n; scanf("%d", &n);
int y = n / 10000, m = (n / 100) % 100, d = n % 100;
if((y % 4 == 0 && y % 100) || y % 400 == 0) mon[2] = 29;
string s, hw, AB;
int fhw = 1, fAB = 1;
while(fhw || fAB) {
++d;
if(d > mon[m]) {
++m; d = 1;
if(m > 12) {
++y; m = 1;
if((y % 4 == 0 && y % 100) || y % 400 == 0) mon[2] = 29;
}
}
s = (char)((y/1000%10)+'0');
s += (char)((y/100%10)+'0');
s += char(y/10%10+'0');
s += char(y%10+'0');
s += char(m/10%10+'0');
s += char(m%10+'0');
s += char(d/10%10+'0');
s += char(d%10+'0');
if(fhw && ishw(s)) fhw = 0, hw = s;
if(fAB && isAB(s)) fAB = 0, AB = s;
}
cout << hw << "\n" << AB << "\n";
return 0;
}
答案:
题意:点此进入
做法:50分的数据方法挺多的,记录字母前缀和再枚举等等。而100分的做法其实是最短小的(又是考场做不出来系列),正确做法复杂度是O(n),统计每个字母的贡献,即这个字母出现在多少个区间中,权值和就是答案。而“每个字母出现在多少个区间中”用如下公式: ( i ? p r e [ s [ i ] ? ′ a ′ ] ) ? ( l e n ? i + 1 ) (i-pre[s[i]-'a']) * (len-i+1) (i?pre[s[i]?′a′])?(len?i+1),其中pre[s[i]-‘a’]代表的是上一个相同字母出现的位置, 而这个公式计算的是,包含i左端点的数量*包含i右端点的数量,要减去上一个相同字母出现的位置是防止重复计算(想不出来系列)。
代码:
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint int
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
int f = 1; res = 0;
char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int pre[30];
char s[N];
int main() {
scanf("%s", s+1);
int len = strlen(s+1);
LL res = 0;
_rep(1, len, i) {
res += 1ll * (i-pre[s[i]-'a']) * (len-i+1);
pre[s[i]-'a'] = i;
}
cout << res;
return 0;
}
复制代码 代码如下: % URL="http://news.163.com/special/00011K6L/rss_newstop....
错误描述: 在开发.net项目中,通过microsoft.ACE.oledb读取excel文件信息时,报...
正则忽略大小写 – RegexOptions.IgnoreCase 例如: 复制代码 代码如下: Str = R...
DELETEFROMTablesWHEREIDNOTIN(SELECTMin(ID)FROMTablesGROUPBYName) Min的话保...
工具:Eclipse,Oracle,smartupload.jar;语言:jsp,Java;数据存储:Oracle。...
Elasticsearch 是通过 Lucene 的倒排索引技术实现比关系型数据库更快的过滤。特...
上篇文章给大家介绍了 Java正则表达式匹配,替换,查找,切割的方法 ,接下来,...
4月11日20:30~22:00通过腾讯会议进行了第二次在线学习讨论我把学习笔记整理一下...
项目中用到的一些特殊字符和图标 html代码 XML/HTML Code 复制内容到剪贴板 div ...
本文实例讲述了Laravel框架源码解析之反射的使用。分享给大家供大家参考,具体如...