HDU 3082 HDOJ 3082 Simplify The Circuit ACM 3082 IN HDU
Posted on 2010-10-28 22:23 MiYu 閱讀(676) 評論(0) 編輯 收藏 引用 所屬分類: ACM ( 模擬 ) 、ACM ( 水題 )
MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=3082
題目分析:
沒什么特殊的方法, 簡單模擬就可以了 :
代碼 :

/*
Mail to : miyubai@gamil.com
My Blog : www.baiyun.me
Link : http://www.cnblogs.com/MiYu || http://m.shnenglu.com/MiYu
Author By : MiYu
Test : 1
Complier : g++ mingw32-3.4.2
Program : HDU_3082
Doc Name : Simplify The Circuit
*/
//#pragma warning( disable:4789 )
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
char str[110];
char *tok;
int main ()
{
int T;
scanf ( "%d",&T );
while ( T -- ) {
int N;
double res = 0;
scanf ( "%d", &N );
for ( int i = 1; i <= N; ++ i ) {
scanf ( "%s", str );
tok = strtok ( str, "-" );
int t = atoi ( tok );
int r = t;
while ( tok = strtok ( NULL, "-" ) ) {
t = atoi ( tok );
r += t;
}
res += 1.0 / r;
}
printf ( "%.2lf\n", 1.0 / res );
}
return 0;
}
Mail to : miyubai@gamil.com
My Blog : www.baiyun.me
Link : http://www.cnblogs.com/MiYu || http://m.shnenglu.com/MiYu
Author By : MiYu
Test : 1
Complier : g++ mingw32-3.4.2
Program : HDU_3082
Doc Name : Simplify The Circuit
*/
//#pragma warning( disable:4789 )
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
char str[110];
char *tok;
int main ()
{
int T;
scanf ( "%d",&T );
while ( T -- ) {
int N;
double res = 0;
scanf ( "%d", &N );
for ( int i = 1; i <= N; ++ i ) {
scanf ( "%s", str );
tok = strtok ( str, "-" );
int t = atoi ( tok );
int r = t;
while ( tok = strtok ( NULL, "-" ) ) {
t = atoi ( tok );
r += t;
}
res += 1.0 / r;
}
printf ( "%.2lf\n", 1.0 / res );
}
return 0;
}