| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
又是个水題#include <stdio.h>
#include <string.h>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
struct array{
int D;
int C[16], L[16], U[16];
void js();
void jsAddr(string, int*);
};
map<string, array> arrays;
void array::js(){
for(int d = D-1; d > 0; d--){
C[d] = C[d+1] * (U[d+1]-L[d+1]+1);
}
for(int d = 1; d <= D; d++){
C[0] -= C[d] * L[d];
}
}
void array::jsAddr(string name, int *pos){
int addr = C[0];
for(int i = 1; i <= D; i++) addr += C[i] * pos[i];
cout << name << "[";
for(int i = 1; i <= D; i++){
cout << pos[i] << (i==D? "] = ": ", ");
}
cout << addr << endl;
}
int main(int argc, char **argv){
int arrayNum, addNum;
cin >> arrayNum >> addNum;
for(int i = 0; i < arrayNum; i++){
string name;
array tmp;
int sz;
cin >> name >> tmp.C[0] >> sz >> tmp.D;
tmp.C[tmp.D] = sz;
for(int j = 1; j <= tmp.D; j++){
cin >> tmp.L[j] >> tmp.U[j];
}
tmp.js();
arrays.insert(pair<string, array>(name, tmp));
}
for(int i = 0; i < addNum; i++){
string name;
cin >> name;
map<string, array>::iterator it = arrays.find(name);
int pos[16];
int dim = it->second.D;
for(int i = 0; i < dim; i++) cin >> pos[i];
it->second.jsAddr(name, pos-1);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator