您的位置:首页 > 其它

Codeforces Round #324 (Div. 2) A, B, C, D, E

2015-10-09 16:13 363 查看
A. Olesya and Rodion

题目链接:

  codeforces 584A. Olesya and Rodion

题目描述:

  给出n, t, 问是否存在一个n位数能被t整除,能的话输出这个数,否则输出-1. 题目太水,加上题目描述是为了确保此题是此题,此题非彼题(看的是同一个题目)

解题思路:

  当n=1,t=10时输出-1,其他时候先输出一个t,然后其他剩余的位置用0填补。

题目代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 2010;
int a[maxn], b[maxn], posb[maxn];
struct node
{
int x, y;
node (int a = 0, int b = 0):x(a),y(b) {}
} p[10000000];

int main ()
{
int n;
while (scanf ("%d", &n) != EOF)
{
for (int i=1; i<=n; i++)
scanf ("%d", &a[i]);
for (int i=1; i<=n; i++)
{
scanf ("%d", &b[i]);
posb[b[i]] = i;
}

int res, nu;
res = nu = 0;
for (int i=1; i<=n; i++)
{
int x = i;
for (int j=i-1; j>0; j--)
{
if (posb[a[j]]>=x && posb[a[x]]<=j)
{
swap (a[x], a[j]);
res += abs (x - j);
p[nu ++] = node(x, j);
x = j;
}
}
}

printf ("%d\n%d\n", res, nu);
for (int i=0; i<nu; i++)
printf ("%d %d\n", p[i].x, p[i].y);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: