【Codeforces Round #424 (Div. 2) B】Keyboard Layouts

Link:http://codeforces.com/contest/831/problem/B

Description

两个键盘的字母的位置不一样;
数字键的位置一样;
告诉你第一个键盘按某个键,在第二个键盘上对应哪个键(大写、小写字母)
然后给你一段由第一个键盘输入的文本,问如果用第二个键盘输入,会输出什么.

Solution

用map一一对应就好;

NumberOf WA

0

Reviw

这种对应关系的题,map无敌;

Code

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef set<int> myset;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e3;

struct abc{
    int x,id;
};

int k,n,a[N+100],b[N+100],pre[N+100],ans,tot;
map <int,int> dic;
abc c[N*N+10];

bool cmp(abc a,abc b){
    return a.x < b.x;
}

int main(){
    //Open();
    //Close();
    scanf("%d%d",&k,&n);
    rep1(i,1,k)
        scanf("%d",&a[i]);
    pre[0] = 0;
    rep1(i,1,k)
        pre[i] = pre[i-1] + a[i];
    rep1(i,1,n)
        scanf("%d",&b[i]);
    rep1(i,1,k){
        rep1(j,1,n){
            int x = b[j]-pre[i];
            tot++;
            c[tot].x = x,c[tot].id = j;
        }
    }
    sort(c+1,c+1+tot,cmp);
    rep1(i,1,tot){
        int num = n;
        int j = i;
        while (j+1<=tot && c[j+1].x==c[i].x) j++;
        rep1(k,i,j){
            if (dic[c[k].id]!=i){
                num--;
                dic[c[k].id] = i;
            }
        }
        if (num==0) ans++;
        i = j;
    }
    printf("%d
",ans);
    return 0;
}

/*
    写完之后,明确每一步的作用
*/
原文地址:https://www.cnblogs.com/AWCXV/p/7626196.html