zoukankan      html  css  js  c++  java
  • 【每日一题】 UVA

    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:
    ", ++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)
    ", f1,0);
                else printf("    (%d,%d)
    ", f1, f2);
            }
        }
        
    
        //cin >> n;
    }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    用prototype属性来模拟一下类的继承
    Ajax 教程:Ajax 入门简介
    Ajax工作原理
    最新的Ajax教程和技术(上篇)
    javascript面向对象技术基础
    浏览器对象模型
    jQuery (选择器,属性,筛选,文档处理)
    shell(一)
    ntpntpdate时间同步
    centos7新系统安装
  • 原文地址:https://www.cnblogs.com/SuuT/p/9419501.html
Copyright © 2011-2022 走看看