每日一题 UVA - 340 阅读理解+模拟

https://cn.vjudge.net/problem/UVA-340

题目很难读,差不多读了两天

意思是给你一个n个数的数列,然后有m个询问,每个询问也是一个n个数的数列,让你输出两个数:一个是数相同且位置相同的数的总数,另一个是数相同但位置不同的总数。不过有一个蛋疼的约束:

“Two matches (i, j) and (p, q) are called independent when i = p if and only if j = q.

Two matches (i, j) and (p, q) are called independent when i = p if and only if j = q.

Two matches (i, j) and (p, q) are called independent when i = p if and only if j = q...”读了无数遍,最终结论是你数相同但位置不同的总数时必须一一对应(映射),不能出现双射的情况。

然后就开始瞎搞,for两遍

#define _CRT_SECURE_NO_WARNINGS
#include    <cmath>
#include <iostream>
#include    <stdio.h>
#include<algorithm>
#include        <map>
#include     <cstring>
#include      <time.h>
#include      <string>
using namespace std;
#define rep(i,t,n)  for(int i =(t);i<=(n);++i)
#define per(i,n,t)  for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
const int maxn = 1000 + 5;
const long long mod = 1e9 + 7;
int n; int sum = 0;
int a[maxn]; int b[maxn]; int t[maxn];
int cnt[10];
bool cmp(int a, int b) { return a > b; }
char M[256];



int main() {    
    int kase = 0;
    while (cin >> n && n) {
        printf("Game %d:\n", ++kase);
        
        rep(i, 1, n) {
            scanf("%d", &a[i]);
        }
        while (cin >> b[1]) {
            mmm(cnt, 0);
            int f1 = 0, f2 = 0;
            rep(i, 2, n )scanf("%d", &b[i]);
            //rep(i, 1, n)t[i] = a[i];
            if (b[1] == 0)break;
            rep(i, 1, n)if (a[i] == b[i])f1++, b[i] = 0;
            else {
                cnt[a[i]]++;
            }
            rep(i, 1, n)if (cnt[b[i]])f2++,cnt[b[i]]--;

            if(f1==n)printf("    (%d,%d)\n", f1,0);
            else printf("    (%d,%d)\n", f1, f2);
        }
    }
    

    //cin >> n;
}

猜你喜欢

转载自www.cnblogs.com/SuuT/p/9419501.html