Codeforces edu 6 ABCDEF

套题链接: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值