#include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<map> #include<algorithm> #include<vector> #include<iostream> struct array { char name[20]; int base; int bytesize; int d; }; struct dimension { int lowerbound; int upperbound; }; using namespace std; int main() { /*freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);*/ int i,j,k,l,m,n,numberofarray,testcase; scanf("%d %d\n",&numberofarray,&testcase); struct array a[numberofarray]; struct dimension *dim[numberofarray]; map<string,int>str; for(i=0;i<numberofarray;i++) { scanf("%s %d %d %d",&a[i].name,&a[i].base,&a[i].bytesize,&a[i].d); str[a[i].name]=i; dim[i]=(struct dimension*)malloc(a[i].d*(sizeof(struct dimension))); for(j=0;j<a[i].d;j++) { scanf("%d %d",&m,&n); dim[i][j].lowerbound=m; dim[i][j].upperbound=n; } } string s; for(l=0;l<testcase;l++) { cin >> s; cout << s<< '['; int id=str[s]; int d=a[id].d,base=a[id].base,bytesize=a[id].bytesize; int bsize[d+1],indexsize[d+1]; for(i=0;i<d;i++) { cin >> n; if(i>0)cout<<", "; cout << n; indexsize[i]=dim[id][i].upperbound-dim[id][i].lowerbound+1; bsize[i]=n-dim[id][i].lowerbound; } int byte=0;; for(i=0;i<d;i++) { n=bsize[i]; for(j=i+1;j<d;j++)n=n*indexsize[j]; byte+=n; } base=base+byte*bytesize; cout << "] = "<<base<< endl; } return 0; }
Sunday, August 17, 2014
uva: 394 - Mapmaker
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment