Math库
Pi的定义 4 × atan(1.0)
atan(1.0) = 45° = Pi/4 弧度
<Map>
#include <map>
map <string, int> s; 将string与int相互映射
添加数据 s.insert( pair<string, int>(string, int) );
查询数据的个数 s.count(string) == 0 表示不存在
查询数据 s.find(string) -> second 找到对应的int
s.find(int) -> first 找到对应的string
删除数据 s.erase(s.find(string)) / s.erase(s.find(int)) (先保证该数据存在)
清空数据 s.clear
贴一道用Map映射写过的题 POJ 2263 (FLOYD 变式)Code如下:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
#define foru(i, a, b) for (int i=a; i<=b; i++)
#define ford(i, a, b) for (int i=a; i>=b; i--)
#define N 210
#define M 40000
int n, m, w;
int s, t, T;
map <string, int> str;
int f[N][N];
int get(string s){
if (str.count(s) == 0){
w ++;
str.insert(pair<string, int>(s, w));
return w;
}
return str.find(s) -> second;
}
void init(){
str.clear();
char u[50], v[50]; w = 0;
memset(f, 0, sizeof(f));
foru(i, 1, m){
int a, b, c;
scanf("%s %s %d", &u, &v, &c);
a = get((string)u); b = get((string)v);
f[a][b] = f[b][a] = max(f[a][b], c);
}
scanf("%s %s", &u, &v);
s = get(u); t = get(v);
}
void solve(){
foru(k, 1, w)
foru(i, 1, w)
foru(j, 1, w)
f[i][j] = max(f[i][j], min(f[i][k], f[k][j]));
T++;
printf("Scenario #%d\n", T);
printf("%d tons\n\n", f[s][t]);
}
int main(){
freopen("B.txt", "r", stdin);
while ( scanf("%d %d", &n, &m) != EOF && n && m){
init();
solve();
}
return 0;
}