ZOJ 3708 Density of Power Network (water problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.