本文最后更新于404 天前,其中的信息可能已经过时,如有错误请发送邮件到3021714482@qq.com
配置环境
1.安装dev-cpp
2.配置C++11(配置-std=c++11)
3.C/C++/C++11 选择 C++11
考点分析+经验分享
1.可以不写正解,但是一定要会暴力。
2.枚举月份和年份。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool yn(ll x) {
return x % 4 == 0 && x % 100 != 0 || x % 400 == 0;
}
int main() {
for(int year = 2000; year <= 2025; year ++) {
for(int mouth = 1; mouth <= 12; mouth ++) {
ll flag = yn(year) && mouth == 2;
for(int day = 1; day <= m[mouth] + flag; day ++) {
cout << year << " " << mouth << " " << day << "\n";
}
}
}
return 0;
}
3.暴力神级工具next_permutation。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[5] = {0, 1, 2, 3, 4};
int main() {
do {
for(int i = 1; i <= 4; i ++) {
cout << a[i] << " ";
}
cout << "\n";
}while(next_permutation(a + 1, a + 5));
return 0;
}
4.官方文档。
5.结构体排序。
6.染色。
7.前后缀思想(记录$f_i$ 表示前 $i$ 项的最大或最小值)。
- 对于双重循环优化:我们可以只枚举其中一个,去看能不能快速计算另外一个的可能解。
8.一定要自信。
9.存图。
10.二分答案。
11.质数筛。
12.并查集。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5 + 5;
ll n, q, fa[MAXN];
void init_set(int n) {
for(int i = 1; i <= n; i ++) {
fa[i] = i;
}
}
ll find_set(ll x) {
return fa[x] = fa[x] == x ? fa[x] : find_set(fa[x]);
}
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if(x == y) return;
fa[x] = y;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> q;
init_set(n);
while(q --) {
ll opt, x, y;
cin >> opt >> x >> y;
if(opt == 1) union_set(x, y);
else{
if(find_set(x) == find_set(y)) cout << "Y\n";
else cout << "N\n";
}
}
return 0;
}
对拍
优先推荐先去自己想点样例,手玩几组样例。
时间宽裕的话,可以去写对拍。
A.cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b;
int main() {
cin >> a >> b;
if(a == 0) return 0;
cout << a + b << "\n";
return 0;
}
std.cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b;
int main() {
cin >> a >> b;
cout << a + b << "\n";
return 0;
}
make.cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
srand(time(0));//随机数种子
int a = rand() % 10;
int b = rand() % 10;
cout << a << " " << b << "\n";
return 0;
}
pai.cpp
#include<bits/stdc++.h>
using namespace std;
int main() {
while(1) {
system("make.exe > in.in");
system("A.exe < in.in > A.out");
system("std.exe < in.in > std.out");
if(system("fc A.out std.out")) {
cout << "WA\n";
return 0;
} else {
cout << "AC\n";
}
}
return 0;
}
一定要记得编译完所有文件再运行 pai.cpp