UVa 394 Mapmaker

 1  #include <stdio.h>
 2  #include <stdlib.h>
 3  #include <iostream>
 4  #include <algorithm>
 5  #include <vector>
 6  #include <map>
 7  using namespace std;
 8  typedef pair<int,int> ii;
 9  struct matrix
10  {
11      int base,size_,d;
12      vector<ii> v;
13  };
14  int main()
15  {
16      int n,q;
17      while(cin>>n>>q)
18      {
19          map<string,matrix> m;
20          for(int i=0; i<n; i++)
21          {
22              matrix tmp;
23              string mname;
24              cin>>mname>>tmp.base>>tmp.size_>>tmp.d;
25              for(int j=0; j<tmp.d; j++)
26              {
27                  int a,b;
28                  cin>>a>>b;
29                  tmp.v.push_back(ii(a,b));
30              }
31              m[mname]=tmp;
32          }
33          string qname;
34          for(int i=0; i<q; i++)
35          {
36              int ans=0,sum=0;
37              cin>>qname;
38              matrix tmpq=m[qname];
39              int tmpd=tmpq.d,tmpb=tmpq.base;
40              int range[15];
41              for(int j=0; j<tmpd; j++) cin>>range[j];
42              for(int j=0; j<tmpd; j++)
43              {
44 
45                  sum=range[j]-tmpq.v[j].first;
46                  for(int k=j+1; k<tmpd; k++)
47                  {
48                      sum*=(tmpq.v[k].second-tmpq.v[k].first+1);
49 
50                  }
51                  ans+=sum;
52              }
53              printf("%s[",qname.c_str());
54              for(int j=0;j<tmpd;j++)
55              {
56                  printf("%d",range[j]);
57                  if(j!=tmpd-1) printf(", ");
58              }
59              printf("] = %d\n",tmpq.base+ans*tmpq.size_);
60 
61          }
62      }
63      return 0;

64  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble