From e4925cdc51a6427d6f566a8c7036d8dd4b6b3169 Mon Sep 17 00:00:00 2001 From: qzane Date: Thu, 25 Dec 2014 23:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9F=E7=89=A9=E9=93=BE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=A5=BD=E4=B9=85=E6=89=8D=E8=BF=87...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 13307130226/assignment13/1094.cpp | 61 +++++++++++++++++++ 13307130226/assignment13/bk.1094.cpp | 71 ++++++++++++++++++++++ 13307130226/assignment13/p1.cpp | 90 ++++++++++++++++++++++++++++ 13307130226/assignment13/p2.cpp | 59 ++++++++++++++++++ 13307130226/assignment13/p3.cpp | 64 ++++++++++++++++++++ 5 files changed, 345 insertions(+) create mode 100644 13307130226/assignment13/1094.cpp create mode 100644 13307130226/assignment13/bk.1094.cpp create mode 100644 13307130226/assignment13/p1.cpp create mode 100644 13307130226/assignment13/p2.cpp create mode 100644 13307130226/assignment13/p3.cpp diff --git a/13307130226/assignment13/1094.cpp b/13307130226/assignment13/1094.cpp new file mode 100644 index 0000000..9472b64 --- /dev/null +++ b/13307130226/assignment13/1094.cpp @@ -0,0 +1,61 @@ +#include +#include +using namespace std; + +int gre[300][300]; +int val[300]; +int n,m; +string tmp; +string ans; +bool nright; +bool nn; + +bool check(int times){ + for(int i=0;i=0;--i) + ans +=(char)val[i]; + ans += '.'; + return true; +} + +int main(){ +while(1){ + cin >> n >> m; + if(n == 0 && m == 0) + break; + for(int i='A';i<'A'+n;++i) + for(int j='A';j<'A'+n;++j) + gre[i][j]=0; + nright=nn=false; + ans = "Sorted sequence cannot be determined."; + for(int ii=0;ii> tmp; + if(nn)continue; + int a,b; //a +#include +#include +#include +using namespace std; +int n,m; +int big[300][300]; +int sma[300][300]; +char order[300]; +int i,j,g,h; +string tmp; +bool nright,occo; +int num_n; +bool check(int nn){ + bool nright=false; + for(int i='A';i<'A'+n;++i){ + big[i][0]=0; + for(int j='A';j<'A'+n;++j) + if(big[i][j]==1)++big[i][0]; + //cout << (char)i << big[i][0] << endl; + } + for(int i=n-1;i>=0;--i){ + order[i]=-1; + for(int j='A';j<'A'+n;++j) + if(big[j][0]==i) + order[i]=j; + if(order[i]==-1){ + nright=true;} + } + if(nright)return false; + else{ + cout << "Sorted sequence determined after "<=0;--i) + cout << order[i]; + cout <<'.'<< endl; + } + return true; + +} +int main(){ +while(1){ + cin >> n >> m; + cin.sync(); + if(n == 0 && m == 0) + break; + cout << "mn" << n << m << endl << flush; + nright = false; + for(int i='A';i<='Z';++i) + for(int j='A';j<='Z';++j) + big[i][j]=sma[i][j]=0; + for(int i=0;i> tmp;//g +#include +#include +#include +#include +using namespace std; + +int P,T; +class way{ +public: + int a,w; + bool operator<(const way& a)const{ + return a.w>w; + } +}tmp; +vector >ways; + +vectordis; +vector >from; +class comp{ +public: + bool operator()(int a,int b){ + return dis[a]>dis[b]; + } +}; +priority_queue,comp>points; +const int shif = 14; +const int mask = 0x3fff; +setocco; +const int MAXD = 80000000; +void dfs(int now){ + //cout << "dfs " << now <<' '<::iterator i=from[now].begin();i!=from[now].end();++i){ + //cout << ((*i)&mask) << endl; + occo.insert(*i); + if(((*i)&mask)!=0) + dfs((*i)&mask); + } +} +int main(){ + cin >> P >> T; + ways.resize(P); + dis.resize(P); + from.resize(P); + for(int i=0;i> a >> b >> w; + tmp.a=b;tmp.w=w; + ways[a].push_back(tmp); + tmp.a=a; + ways[b].push_back(tmp); + } + while(!points.empty())points.pop(); + dis[0]=0; + points.push(0); + while(!points.empty()){ + int now; + now = points.top(); + points.pop(); + //cout << now << endl; + if(dis[now]>dis[P-1])break; + for(int i=0;idis[now]+w){ + dis[b]=dis[now]+w; + from[b].clear(); + from[b].insert((i<::iterator i=occo.begin();i!=occo.end();++i) + ans += ways[(*i)&mask][(*i)>>shif].w; + cout << (ans<<1) << endl; +return 0; +} \ No newline at end of file diff --git a/13307130226/assignment13/p2.cpp b/13307130226/assignment13/p2.cpp new file mode 100644 index 0000000..eb19072 --- /dev/null +++ b/13307130226/assignment13/p2.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; + +int N,K; +int set[55000]; +int rank[55000]; +int ans; +void getset(int a){ + + //cout << "b " << a << ' ' << set[a] << ' ' <> N >> K; + ans = 0; + for(int i=0;i<=N;++i){ + set[i]=i; + rank[i]=0; + } + for(int i=0;i> d >> x >> y; + if(x>N||y>N){ + ++ans; + //cout << "lie" << endl; + continue;} + getset(x);getset(y); + if(d==1){ + if(set[x]==set[y]&&(-rank[x]+rank[y]+3)%3!=0) + {++ans; + //cout << "lie" << endl; + } + if(set[x]!=set[y]){ + rank[set[y]]=3+rank[x]-rank[y]; + set[set[y]]=set[x]; + } + }else if(d==2){ + if(set[x]==set[y]&&(rank[x]-rank[y]+3)%3!=1) + {++ans; + //cout << "lie" << endl; + } + if(set[x]!=set[y]){ + rank[set[x]]=3-rank[x]+rank[y]+1; + set[set[x]]=set[y]; + } + }/* + for(int i=0;i<9;++i){ + cout << 'r' << i << set[i] << rank[i]%3 << endl; + } */ + } + + cout << ans << endl; +} \ No newline at end of file diff --git a/13307130226/assignment13/p3.cpp b/13307130226/assignment13/p3.cpp new file mode 100644 index 0000000..b83b7f8 --- /dev/null +++ b/13307130226/assignment13/p3.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +int N,s,p; +int pointsX[600],pointsY[600]; +int sets[600]; +int nset; +double ans; +class way{ +public: + double lo; + int a,b; + way(){ + lo=0.0; + a=b=0; + } + bool operator<(const way& a)const{ + return a.loways; +way tmp; +int main(){ +cin >> N; +while(N--){ + cin >> s >> p; + for(int i=0;i> pointsX[i] >> pointsY[i]; + sets[i]=i; + } + while(!ways.empty())ways.pop(); + for(int i=0;itmp.lo?ans:tmp.lo; + sets[sets[tmp.a]]=sets[tmp.b]; + if(nset==s)break; + } + printf("%0.2f",sqrt(ans)); + cout << endl; +} +return 0; +} \ No newline at end of file