套题链接:http://codeforces.com/contest/620
难度类型:难度跨度较大,前三题容易,后三题比较难,最后一题数据水其实不难。
A
题解
类型:数学
算 x,y 坐标之差的最大值即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
int main()
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
printf("%d\n", max(abs(x1-x2), abs(y1-y2)));
return 0;
}
B
题解
类型:模拟
统计用的条子个数,打表预处理前缀即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
const int N = 1E6+5;
int a[N];
LL sum[N];
int b[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main()
{
for (int i = 1; i <= 1000000; i++) {
a[i] = b[i%10]+a[i/10];
sum[i] = sum[i-1]+a[i];
}
int l, r;
scanf("%d%d", &l, &r);
printf("%I64d\n", sum[r]-sum[l-1]);
return 0;
}
C
题解
类型:贪心
基本的想法是碰到两个就直接形成一组,用个set来维护就行了。
所有的点都要划入一个划分对左右区间做些处理即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
const int N = 3E5+5;
vector<PII> v;
set<int> s;
int main()
{
int n, x, l = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (s.find(x) != s.end()) {
v.pb(mp(l, i));
l = i+1;
s.clear();
} else {
s.insert(x);
}
}
if (v.empty()) {
puts("-1");
} else {
printf("%d\n", v.size());
v[v.size()-1].se = n;
for (int i = 0; i < v.size(); i++) {
printf("%d %d\n", v[i].fi, v[i].se);
}
}
return 0;
}
D
题解
类型:二分,枚举
另开题解传送门:http://blog.csdn.net/xc19952007/article/details/50597254
E
题解
类型:图论,线段树
另开题解传送门:http://blog.csdn.net/xc19952007/article/details/50598125
F
题解
类型:枚举
数据比较水,可以平方水过去,学到了一些优化的技巧。
另开题解传送门:http://blog.csdn.net/xc19952007/article/details/50598152