Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3708
Test instructions
Test instructions is very simple, is to count how many kinds of lines, and the number of buses. The picture of the topic is very frightening, if this is fooled by the words will be miserable, the provincial race when each problem should be carefully read, so as not to cause unnecessary losses.
Solution One:
Teammates use a two-dimensional graph to indicate that if the corresponding position has been marked, do not add a count, if not marked, the mark, and count the value plus one.
Code:
#include <iostream> #include <string> #include <iomanip> #include <cstring>using namespace std; int A[505],b[505];int Map[505][505];int main () {int t,bus,m;cin>>t;while (t--) {cin>>bus>>m; memset (map,0,sizeof (map)), int sum=0;for (int i=1;i<=m;i++) {cin>>a[i];} for (int i=1;i<=m;i++) {cin>>b[i];} for (int i=1;i<=m;i++) {if (map[a[i]][b[i]]| | Map[b[i]][a[i]]) continue;else{map[a[i]][b[i]]=1; sum++; }} Double ans;ans=sum*1.0/(bus*1.0); Cout<<fixed<<setprecision (3) <<ans<<endl;}
Solution Two:
My idea is that you can multiply the small one by 1000 (because the raw data is up to 500, so you can differentiate), and with the big one, it's OK to use set to row the weight.
Code:
#include <iostream> #include <string> #include <iomanip> #include <set> #include <algorithm >using namespace Std;int a[505],b[505]; int main () {int T,bus,m,minn,maxx;cin>>t;while (t--) {set <int> cnt;cin>>bus>>m;for (int i=1;i <=m;i++) {cin>>a[i];} for (int i=1;i<=m;i++) {cin>>b[i];} for (int i=1;i<=m;i++) {minn=min (a[i],b[i]); Maxx=max (A[i],b[i]); Cnt.insert (Minn*1000+maxx);} Double Ans;ans=cnt.size () *1.0/bus;cout<<fixed<<setprecision (3) <<ans<<endl;} return 0;}
ZOJ 3708 Density of Power Network (water problem)