zoukankan      html  css  js  c++  java
  • HDU 4941

    Magical Forest



    Problem Description
    There is a forest can be seen as N * M grid. In this forest, there is some magical fruits, These fruits can provide a lot of energy, Each fruit has its location(Xi, Yi) and the energy can be provided Ci. 

    However, the forest will make the following change sometimes: 
    1. Two rows of forest exchange. 
    2. Two columns of forest exchange. 
    Fortunately, two rows(columns) can exchange only if both of them contain fruits or none of them contain fruits. 

    Your superior attach importance to these magical fruit, he needs to know this forest information at any time, and you as his best programmer, you need to write a program in order to ask his answers quick every time.
     

    Input
    The input consists of multiple test cases. 

    The first line has one integer W. Indicates the case number.(1<=W<=5)

    For each case, the first line has three integers N, M, K. Indicates that the forest can be seen as maps N rows, M columns, there are K fruits on the map.(1<=N, M<=2*10^9, 0<=K<=10^5)

    The next K lines, each line has three integers X, Y, C, indicates that there is a fruit with C energy in X row, Y column. (0<=X<=N-1, 0<=Y<=M-1, 1<=C<=1000)

    The next line has one integer T. (0<=T<=10^5)
    The next T lines, each line has three integers Q, A, B. 
    If Q = 1 indicates that this is a map of the row switching operation, the A row and B row exchange. 
    If Q = 2 indicates that this is a map of the column switching operation, the A column and B column exchange. 
    If Q = 3 means that it is time to ask your boss for the map, asked about the situation in (A, B). 
    (Ensure that all given A, B are legal. )
     

    Output
    For each case, you should output "Case #C:" first, where C indicates the case number and counts from 1.

    In each case, for every time the boss asked, output an integer X, if asked point have fruit, then the output is the energy of the fruit, otherwise the output is 0.
     

    Sample Input
    1 3 3 2 1 1 1 2 2 2 5 3 1 1 1 1 2 2 1 2 3 1 1 3 2 2
     

    Sample Output
    Case #1: 1 2 1

     题意:给出一个矩阵中的数字。有调换行和列的操作。操作完后问在(x,y)处的是什么数字。

    sl: 很逗得模拟。 直接保留开始的位置就好了。map以下就能搞。

     1 // by caonima
     2 // hehe
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <vector>
     7 #include <map>
     8 using namespace std;
     9 const int MAX= 1e5+10;
    10 struct node {
    11     int x,y,val;
    12 }v[MAX];
    13 int cas,n,m,k;
    14 map<pair<int,int>,int> hash;
    15 map<int,int> lastx,lasty;
    16 int Q,A,B;
    17 void init() {
    18     for(int i=1;i<=k;i++) {
    19 //        col[v[i].x]=v[i].x;
    20 //        com[v[i].y]=v[i].y;
    21         lastx[v[i].x]=v[i].x;
    22         lasty[v[i].y]=v[i].y;
    23     }
    24 
    25 }
    26 void gao1() {
    27     scanf("%d %d",&A,&B);
    28     int t=lastx[A];
    29     lastx[A]=lastx[B];
    30     lastx[B]=t;
    31    // swap(col[A],col[B]);
    32 }
    33 void gao2() {
    34     scanf("%d %d",&A,&B);
    35     int t=lasty[A];
    36     lasty[A]=lasty[B];
    37     lasty[B]=t;
    38    // swap(com[A],com[B]);
    39 }
    40 void gao3() {
    41     scanf("%d %d",&A,&B);
    42     int x=lastx[A],y=lasty[B];
    43     int ans=hash[make_pair(x,y)];
    44     printf("%d ",ans);
    45 }
    46 int main() {
    47     int cnt=0;
    48     scanf("%d",&cas);
    49     while(cas--) {
    50         scanf("%d %d %d",&n,&m,&k);
    51         hash.clear();
    52 
    53         for(int i=1;i<=k;i++) {
    54             scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].val);
    55             hash[make_pair(v[i].x,v[i].y)]=v[i].val;
    56         }
    57         init();
    58         int t;
    59         scanf("%d",&t);
    60         printf("Case #%d: ",++cnt);
    61         while(t--) {
    62             scanf("%d",&Q);
    63             if(Q==1) {
    64                 gao1();
    65             }
    66             else if(Q==2) {
    67                 gao2();
    68             }
    69             else {
    70                 gao3();
    71             }
    72         }
    73     }
    74     return 0;

    75 } 

  • 相关阅读:
    为什么我们不要 .NET 程序员
    Jquery异步请求数据实例代码
    关系数据库中表的基本属性有哪些
    利用VC从DLL传递消息到EXE
    新实体与原实体之间为一对多关系
    本人C++ Builder开发的仿Windows桌面应用程序源码
    delphi窗体动态设计 在系统运行时动态更改控件属性
    DB.ASP 用Javascript写ASP很灵活很好用很easy
    CrazyScan Satellite scan software 卫星扫描
    delphi中窗体半透明效果如何实现
  • 原文地址:https://www.cnblogs.com/acvc/p/3908294.html
Copyright © 2011-2022 走看看