1801. Reading books
2013-01-08 23:26
615 查看
//use the method of dividing the books into several subsets
//color the similar books with the same color unless it has been colored
//then read the book with the least time in each subset first
//color the similar books with the same color unless it has been colored
//then read the book with the least time in each subset first
#include <iostream> #include <cstring> #include <set> using namespace std; struct Node{ public: int rank; int t; Node(int i,int j):rank(i),t(j){} bool operator <(const Node &node)const{ t < node.t; } }; set<int> s[100]; int color[100]; void color_set(int k,int c){ if (color[k]!=-1) return; color[k] = c; for(set<int>::iterator it=s[k].begin(); it!=s[k].end(); it++) color_set(*it,c); } int main(){ int n,m; while( cin>>n>>m && n ){ int t[100]; memset(color,-1,sizeof(color)); for(int i=0; i<n; i++){ cin>>t[i]; s[i].clear(); s[i].insert(i); } for(int i=0; i<m; i++){ int a,b; cin>>a>>b; s[a].insert(b); s[b].insert(a); } for(int i=0; i<n; i++) color_set(i,i); int sum = 0; for(int i=0; i<n; i++){ set<int> tmp; for(int j=0; j<n; j++) if (color[j]==i) tmp.insert(t[j]); if (tmp.empty()) continue; sum += *tmp.begin(); tmp.erase(tmp.begin()); for(set<int>::iterator it=tmp.begin(); it!=tmp.end(); it++) sum += (*it)/2; } cout<<sum<<endl; } return 0; }
相关文章推荐
- sicily 1801 Reading books【DFS】
- 1801. Reading books
- BZOJ1801: [Ahoi2009]chess 中国象棋
- BZOJ 1801 [Ahoi2009]chess 中国象棋 递推
- Reading Books
- BZOJ 1801: [Ahoi2009]chess 中国象棋 [DP 组合计数]
- 【codevs 1801】矿工配餐
- BZOJ_1801_[Ahoi2009]chess 中国象棋_DP
- A段架构设计_隽语集(IT+設計思考_1801)
- 【bzoj1801】【AHOI2009】【chess中国象棋】【组合数学】
- net.sf.json.JSONException: Unterminated string at character 1801
- BZOJ1801: [Ahoi2009]chess 中国象棋
- bzoj 1801: [Ahoi2009]chess 中国象棋
- bzoj 1801: [Ahoi2009]chess 中国象棋【dp】
- 1801: [Ahoi2009]chess 中国象棋
- BZOJ 1801 AHOI2009 中国象棋 递归
- bzoj1801(递推)
- 1801: [Ahoi2009]chess 中国象棋
- 1801:斜率计算
- DP【p2051(bzoj 1801)】 [AHOI2009]中国象棋.