会员
周边
捐助
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
windmissing
博客园
首页
新随笔
管理
HDU2254 奥运 矩阵应用
//最原始的矩阵应用,不解释 #include "Mat.h" #include <iostream> #include<map> #include<string> using namespace std; map<string, int> M; Mat mat, temp1, temp2; int main() { int n, cnt, k, t1, t2, ans, a1, a2; string p1, p2, v1, v2; mod = 2008; while(cin>>n) { mat.clear(); M.clear(); cnt = 1; while(n--) { cin>>p1>>p2; if(M[p1] == 0) M[p1] = cnt++; if(M[p2] == 0) M[p2] = cnt++; mat.s[M[p1]][M[p2]]++; } mat.sizei = cnt; mat.sizej = cnt; cin>>k; while(k--) { cin>>v1>>v2>>t1>>t2; if(M[v1]==0||M[v2]==0||(t1==0&&t2==0)) { cout<<0<<endl; continue; } if(t1>t2) swap(t1, t2); temp1 = mat;temp2 = mat; temp1.solve(t2);a1 = temp1.s[M[v1]][M[v2]]; if(t1 <= 1) a2 = 0; else { temp2.solve(t1-1); a2 = temp2.s[M[v1]][M[v2]]; } ans = (a1 - a2 + mod ) % mod; cout<<ans<<endl; } } return 0; }
posted @
2011-12-29 19:38
windmissing
阅读(
116
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部