zoukankan      html  css  js  c++  java
  • 【UVA】434-Matty's Blocks

    一道非常easy想复杂的题,给出主视图和右视图,计算最少能用几个正方体组成相应的视图,以及最多还能加几块正方体。

    求最多加入事实上就是求出最多的正方体数减去最少的,主要就是最少的不好求。

    一開始各种模拟就是不正确,之后发现,仅仅须要统计两个视图的高度个数就能够了(简直了)

    14390495 434 Matty's Blocks Accepted C++ 0.016 2014-10-21 11:35:11

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    #include<map>
    using namespace std;
    const int maxn = 10;
    int mat[maxn][maxn];
    int array[2][maxn];
    int countx[2][maxn];
    int n;
    void display(int x[maxn][maxn]){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++)
                printf("%d ",x[i][j]);
            printf("
    ");
        }
        return;
    }
    int main(){
        int T;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&n);
            memset(countx,0,sizeof(countx));
            for(int i = 0; i < 2; i++)
                for(int j = 0 ;j < n; j++){
                    scanf("%d",&array[i][j]);
                    countx[i][array[i][j]] ++;
                }
            for(int i = 0; i < n; i++)
                for(int j = 0; j < n;j ++)
                    mat[j][i] = array[0][i];
            for(int i = 0,k = n - 1; i < n; i++,k--) //求最大能放几块正方形
                for(int j = 0; j < n; j++)
                    if(mat[k][j] > array[1][i]) mat[k][j] = array[1][i];
            //display(mat);
            int _min = 0,_max = 0;
            for(int i = 0; i < maxn; i++){
                _min += max(countx[0][i],countx[1][i]) * i;
            }
            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++)
                    _max += mat[i][j];
            printf("Matty needs at least %d blocks, and can add at most %d extra blocks.
    ",_min,_max-_min);
        }
        return 0;
    }
    

  • 相关阅读:
    oracle索引
    linux命令
    struts2的配置文件struts.xml详解
    oracle删除一个表中的重复数据,且只保留一条
    初步研究java类的加载机制
    java读取Properties配置文件
    利用oracle闪回来找回被drop的表
    快速排序Quicksort
    树与树的概念
    递归
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4214202.html
Copyright © 2011-2022 走看看