第二屆卓越盃官解

pA

不解釋

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,m; cin>>n>>m; cout<<n*m<<"\n"; }

pB

基礎 for 迴圈,提醒小小的點,當天 js 有上班才可以給錢

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,ret=0; cin>>n; for(int i=0;i<n;++i){ int ct=0; bool tp,js; cin>>tp; ct+=tp; cin>>js; ct+=js; cin>>tp; ct+=tp; if(js){ ret+=4500/ct; } } cout<<ret<<"\n"; }

pC

高速( 複雜度

log(x) )計算次方

#include<bits/stdc++.h> using namespace std; const int MOD=1e9+7; using ll=long long; ll POW(ll a,ll x){ ll ret=1; while(x>0){ if(x&1) ret=ret*a%MOD; a=a*a%MOD; x>>=1; } return ret; } int main(){ ios::sync_with_stdio(0);cin.tie(0); ll n; cin>>n; cout<<(ll)54*POW(2,n)%MOD<<"\n"; }

pD

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,k; cin>>n>>k; int val=0,day; for(int i=0;i<n;++i){ int ct=0; int tp; while(cin>>tp && tp!=0){ ct++; } val+=ct*ct; if(val>=k){ day=i; break; } } cout<<day<<"\n"; }

pE

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,t; cin>>n>>t; vector<vector<int>> dp(2,vector<int>(n+1)); int tp=0; for(int i=1;i<=n;++i){ int ai; cin>>ai; if(tp<=t){ dp[0][i]=max(dp[0][i-1],dp[1][i-1])+ai; }else{ dp[0][i]=dp[1][i-1]+ai; } dp[1][i]=max(dp[0][i-1],dp[1][i-1]); tp=ai; } cout<<max(dp[1][n],dp[0][n])<<"\n"; }

pF

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,q; cin>>n>>q; vector<int> qq(q); for(int i=0;i<q;++i){ cin>>qq[i]; } vector<string> voc(n+1); for(int i=1;i<=n;++i){ cin>>voc[i]; } for(int i=0;i<q;++i){ cout<<voc[qq[i]]<<"\n"; } }

pG

#include<bits/stdc++.h> using namespace std; #define F first #define S second using ll=long long; using pll=pair<ll,ll>; const int N=100010; const ll INF=0x3f3f3f3f3f3f3f3f; int n,m,cp; ll dis[N]; vector<pll> g[N]; bool vis[N]; void solve(){ cin>>n>>m; for(int i=1;i<=m;++i){ int a,b,c; cin>>a>>b>>c; g[a].emplace_back(c,b); g[b].emplace_back(c,a); } fill(dis,dis+n+5,INF); int s,t; cin>>s>>t; dis[s]=0; priority_queue<pll,vector<pll>,greater<pll>> pq; pq.emplace(0,s); while(!pq.empty()){ pll now=pq.top(); pq.pop(); if(now.F>dis[now.S]) continue; dis[now.S]=now.F; for(auto e:g[now.S]){ pq.emplace(e.F+now.F,e.S); } } cout<<dis[t]; } int main(){ ios::sync_with_stdio(0);cin.tie(0); int t=1; while(t--){ solve(); } }

pH

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,t; cin>>n>>t; cin.ignore(); vector<string> dic(t); for(int i=0;i<t;++i){ getline(cin,dic[i]); } for(int i=0;i<n;++i){ int r,c; cin>>r>>c; r--, c--; cout<<dic[r][c]; } }

pI

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0);cin.tie(0); string str; while(cin>>str){ for(int i=0;i<str.size();++i){ if(islower(str[i]) || isupper(str[i])){ cout<<int(str[i]-'a')+50*(str.size()-i-1)<<" "; } } } }

pJ

#include<bits/stdc++.h> using namespace std; struct pt{ int x,y,z; pt(int a=0,int b=0,int c=0){ x=a; y=b; z=c; } }; int main(){ pt l1,l2,p1,p2; cin>>p1.x>>p1.y>>p1.z; cin>>l1.x>>l1.y>>l1.z; cin>>p2.x>>p2.y>>p2.z; cin>>l2.x>>l2.y>>l2.z; int d = l1.x*l2.y - l1.y*l2.x; int dx= (p2.x - p1.x)*l2.y - (p2.y - p1.y)*l2.x; int dy= l1.x*(p2.x - p1.x) - l1.y*(p2.y - p1.y); int t=dx/d,k=dy/d; cout<<l1.x*t+p1.x<<" "<<l1.y*t+p1.y<<" "<<l1.z*t+p1.z<<"\n"; }