I didn't have time to watch the opening ceremony in the morning. When I came to the computer room, I was surprised to find that:
I also Ke with water one site than match Yes ! q w q \red {I have another race with water! qwq} I have another race with water! qwq
T 1 : T1: T1: P 2296 [ N O I P 2014 carry high group ] search look for Avenue road P2296 [NOIP2014 improvement group] find the way P2296[NOIP2014 improvement group] find the way
Expected score: 100 p t s 100pts 100pts
Actual score: 90 p t s 90pts 90pts
Idea:
When I got the title, I found that it was a graph theory title I often played recently. The title was very simple and had no complex background. The meaning of the question is to find the shortest path problem with requirements for path nodes. For the problem that all the points connected on the shortest circuit must be directly or indirectly connected with the end point, it was immediately thought of building a reverse diagram and taking the end point as the starting point d f s dfs dfs, the point not found is the unreachable point, marked with t a g tag tag. Then traverse the node array and type t a g tag All the points connected by the tag points are marked again t a g tag tag.
Since the edges of the graph are not weighted, the b f s bfs bfs, hit t a g tag The point of tag can be ignored directly and the shortest path can be found.
Complexity is Θ ( N ) \Theta(N) Θ(N), 3 m i n 3min 3 minutes to come up with ideas, 10 m i n 10min 10min to output the code. 3 m s 3ms 3ms passed steadily.
But R E \purple{RE} Did you get a point? q w q q w q qwqqwq qwqqwq
C u t e C o d e : \pink{Cute\space Code:} Cute Code:
#include<bits/stdc++.h> using namespace std; const int maxn=1e4; int n,m,s,t; int v[maxn],is[maxn],d[maxn],tag[maxn]; vector<int> ver[maxn],fver[maxn]; inline void read() { cin>>n>>m; for(int i=1;i<=m;i++) { int u,v; cin>>u>>v; ver[u].push_back(v); fver[v].push_back(u); } cin>>s>>t; } inline void work(int x) { if(!fver[x].size()) { return; } for(int y=0;y<fver[x].size();y++) { int t=fver[x][y]; if(!v[t]) { v[t]=1; is[t]=1; work(t); } } } inline void make_tag() { for(int i=1;i<=n;i++) { if(!is[i]) { for(int j=0;j<fver[i].size();j++) { tag[fver[i][j]]=0; } } } } inline void bfs() { memset(v,0,sizeof(v)); queue<int> q; d[s]=0; q.push(s); while(q.size()) { int x=q.front();q.pop(); for(int y=0;y<ver[x].size();y++) { int t=ver[x][y]; if(!v[t]&&tag[t]) { v[t]=1; d[t]=d[x]+1; q.push(t); } } } } int main() { memset(tag,1,sizeof(tag)); read(); is[t]=1; work(t); make_tag(); bfs(); if(d[t]) cout<<d[t]<<endl; else cout<<-1<<endl; return 0; }
T 2 : P 1080 [ N O I P 2012 carry high group ] country king swim play T2:P1080 [NOIP2012 improvement group] king game T2:P1080[NOIP2012 improvement group] king game
Expected score: 100 p t s 100pts 100pts
Actual score: 90 p t s 90pts 90pts, why is it 90pts again
Problem solving ideas:
A very interesting math problem, using the idea of greed. The title means to give you two positive integer sequences
{
a
i
}
\{a_i\}
{ai} and
{
b
i
}
;
i
∈
[
1
,
n
]
\{b_i\};i\in[1,n]
{bi}; i ∈ [1,n], you can exchange the positions of each group of elements at will
(
a
i
,
b
i
)
(a_i,b_i)
(ai, bi), but
(
a
1
,
b
1
)
(a_1,b_1)
(a1, b1) cannot move. Make the following function:
f
(
x
)
=
∏
i
=
1
x
−
1
a
i
b
x
,
x
∈
[
2
,
n
]
f(x)=\frac{\prod\limits_{i=1}^{x-1}a_i}{b_x},x\in[2,n]
f(x)=bxi=1∏x−1ai,x∈[2,n]
The maximum value of is the minimum.
Greedy strategy is based on a i × b i a_i\times b_i ai × bi ¢ as the benchmark ( a i , b i ) (a_i,b_i) (ai, bi) in ascending order. It can be proved by the perturbation method in combinatorial mathematics.
Considering the data range, high precision should be opened.
sense sleep to less answer Should yes blue topic q w q , how Do you Just green Yes q w q I think it should be at least \ blue {blue} qwq, how can it be \ green {green} qwq I think it should be blue qwq at least. Why is it green qwq
A C → 90 p t s c o d e AC\to 90pts\space code AC→90pts code
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; struct Wint:vector<int> { Wint(int n=0) { push_back(n); check(); } Wint& check() { while(!empty()&&!back())pop_back(); if(empty())return *this; for(int i=1; i<size(); ++i) { (*this)[i]+=(*this)[i-1]/10; (*this)[i-1]%=10; } while(back()>=10) { push_back(back()/10); (*this)[size()-2]%=10; } return *this; } }; istream& operator>>(istream &is,Wint &n) { string s; is>>s; n.clear(); for(int i=s.size()-1; i>=0; --i)n.push_back(s[i]-'0'); return is; } ostream& operator<<(ostream &os,const Wint &n) { if(n.empty())os<<0; for(int i=n.size()-1; i>=0; --i)os<<n[i]; return os; } bool operator!=(const Wint &a,const Wint &b) { if(a.size()!=b.size())return 1; for(int i=a.size()-1; i>=0; --i) if(a[i]!=b[i])return 1; return 0; } bool operator==(const Wint &a,const Wint &b) { return !(a!=b); } bool operator<(const Wint &a,const Wint &b) { if(a.size()!=b.size())return a.size()<b.size(); for(int i=a.size()-1; i>=0; --i) if(a[i]!=b[i])return a[i]<b[i]; return 0; } bool operator>(const Wint &a,const Wint &b) { return b<a; } bool operator<=(const Wint &a,const Wint &b) { return !(a>b); } bool operator>=(const Wint &a,const Wint &b) { return !(a<b); } Wint& operator+=(Wint &a,const Wint &b) { if(a.size()<b.size())a.resize(b.size()); for(int i=0; i!=b.size(); ++i)a[i]+=b[i]; return a.check(); } Wint operator+(Wint a,const Wint &b) { return a+=b; } Wint& operator-=(Wint &a,Wint b) { if(a<b)swap(a,b); for(int i=0; i!=b.size(); a[i]-=b[i],++i) if(a[i]<b[i]) { int j=i+1; while(!a[j])++j; while(j>i) { --a[j]; a[--j]+=10; } } return a.check(); } Wint operator-(Wint a,const Wint &b) { return a-=b; } Wint operator*(const Wint &a,const Wint &b) { Wint n; n.assign(a.size()+b.size()-1,0); for(int i=0; i!=a.size(); ++i) for(int j=0; j!=b.size(); ++j) n[i+j]+=a[i]*b[j]; return n.check(); } Wint& operator*=(Wint &a,const Wint &b) { return a=a*b; } Wint divmod(Wint &a,const Wint &b) { Wint ans; for(int t=a.size()-b.size(); a>=b; --t) { Wint d; d.assign(t+1,0); d.back()=1; Wint c=b*d; while(a>=c) { a-=c; ans+=d; } } return ans; } Wint operator/(Wint a,const Wint &b) { return divmod(a,b); } Wint& operator/=(Wint &a,const Wint &b) { return a=a/b; } Wint& operator%=(Wint &a,const Wint &b) { divmod(a,b); return a; } Wint operator%(Wint a,const Wint &b) { return a%=b; } Wint pow(const Wint &n,const Wint &k) { if(k.empty())return 1; if(k==2)return n*n; if(k.back()%2)return n*pow(n,k-1); return pow(pow(n,k/2),2); } struct element { Wint l; Wint r; };element ele[10005]; inline bool cmp(element a,element b) { return (a.l*a.r)<(b.l*b.r); } int main() { int n; cin>>n; for(int i=1;i<=n+1;i++) { Wint l,r; cin>>l>>r; ele[i].l=l;ele[i].r=r; } sort(ele+2,ele+n+2,cmp); //for(int i=1;i<=n+1;i++) cout<<i<<":"<<ele[i].l<<" "<<ele[i].r<<endl; Wint ans=1; for(int i=1;i<=n;i++) { ans=ans*ele[i].l; } cout<<ans/ele[n+1].r<<endl; }