青岛农业大学第九届ACM程序设计竞赛
Problem A?喆神裝書
https://ac.nowcoder.com/acm/contest/906/A
題意:是否能夠把所有的書都放在兩個背包里。
題解:貪心
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);if(n>=1)ans=a[n-1]+a[n];cout<<(ans>=sum?"YES":"NO")<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem B?何時收錢
https://ac.nowcoder.com/acm/contest/906/B
題意:如果今年是閏年,那么收的錢是平年的兩倍,為了有更好的規劃,她想知道包括今年在內的連續兩年的收的錢是多少?
題解:
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; bool check(int x){return (x%4==0&&x%100!=0)||x%400==0; } int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){//scanf("%d",&n);scanf("%d%d",&n,&m);if(check(n)){ans=m+m/2;}else{if(check(n+1)) ans=m+m*2;else ans=m+m;}cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem C?找出叛徒
https://ac.nowcoder.com/acm/contest/906/C
題意:一個非空整數數組,除了某個元素只出現一次以外,其余每個元素均出現了三次。輸出那個只出現了一次的元素。
題解:貪心
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&t),a[t]++;for(int i=0;i<=1000;i++)if(a[i]==1)ans=i;cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem D?群神瘋了
https://ac.nowcoder.com/acm/contest/906/D
題意:
一個整數序列 1 ,2 ,... , n。她必須把它分成兩個集合A和B,每個元素恰好屬于一個集合,且令| sum(A)- sum(B) | 最小。
| x | 是x的絕對值,sum(A)是集合A的元素之和。
題解:貪心+思維
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);if(n%4==0)ans=0;if(n%4==1)ans=1;if(n%4==2)ans=1;if(n%4==3)ans=0;cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem E?最小花費
https://ac.nowcoder.com/acm/contest/906/E
題意:n個城市之間建立 (n - 1)條路把這n個城市連接起來,現已知有建立每條路花費的價值為兩個城市的收益之和,把這n個城市連接起來所花費最小值。
題解:貪心
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];sort(a+1,a+n+1);sum+=a[1]*(n-2);cout<<sum<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem F?卑微的Fxx
https://ac.nowcoder.com/acm/contest/906/F
題意:
一個數組,重復k次操作,每次操作都從這個數組中找到最小的不為0的數,輸出這個數,然后把這個數組中所有的數都減去這個數,如果數組中所有的數都為0,則輸出0。
題解:貪心
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d",&n,&k);for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);for(int i=1;i<=k;i++){if(a[i]==a[i-1]&&i<=n){k++;continue;}printf("%d%c",i>n?0:a[i]-sum," \n"[i==k]);sum=a[i];}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem G?迷惑敵人
https://ac.nowcoder.com/acm/contest/906/G
題意:s個士兵,排成一個r行c列,但有兩個"洞"的矩形方隊,缺失士兵數的所有可能值
題解:數學+思維+枚舉
(其中A為缺失士兵數量,x為厚度,當且僅當為整數時成立)
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(ll i=1;i<=n/7;i++){ll a=(n-6*i*i)/(7*i);if((n-6.0*i*i)/(7.0*i)==a&&a>0){cout<<"Possible Missing Soldiers = "<<2*(a*a%MOD)%MOD<<endl;cnt++;}}if(cnt==0){cout<<"No Solution Possible"<<endl;return 0;}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem H?出題人說這是最簡單的題
https://ac.nowcoder.com/acm/contest/906/H
題意:求s到t的最大流
題解:上下界最大流
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; const int Maxn=205; const int Maxm=10005; const int inf=1e9; int n,m,size=1,s,t,tot,ans,S,T,sum; int first[Maxn],tmp[Maxn],in[Maxn],out[Maxn],depth[Maxn]; struct shu{int to,next,len,v;}; shu edge[Maxm<<3];inline int get_int() {int x=0,f=1;char c;for(c=getchar();(!isdigit(c))&&(c!='-');c=getchar());if(c=='-') {f=-1;c=getchar();}for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';return x*f; }inline void build(int x,int y,int z) {edge[++size].next=first[x];first[x]=size;edge[size].to=y;edge[size].len=z; }inline void pre() {T=n+1;for(int i=1;i<=n;i++){int num=in[i]-out[i];if(num>0) build(S,i,num),build(i,S,0),sum+=num;if(num<0) build(i,T,abs(num)),build(T,i,0);} }inline void delet(){for(int i=tot+1;i<=size;i++) edge[i].len=0;}inline int mn(int x,int y){return x < y ? x : y;}inline bool bfs(int s,int t) {queue<int>q; //建議手寫q.push(s);memset(depth,0,sizeof(depth));depth[s]=1;while(!q.empty()){int point=q.front();q.pop();for(int u=first[point];u;u=edge[u].next){int to=edge[u].to;if(edge[u].len && !depth[to]){depth[to]=depth[point]+1;q.push(to);if(to==t) return 1;}}}return 0; }inline int dinic(int point,int flow,int t) {if(point==t) return flow;int sum=0;for(int &u=tmp[point];u&&sum<flow;u=edge[u].next){int to=edge[u].to;if(edge[u].len && depth[to] == depth[point] + 1){int minn=dinic(to,mn(flow-sum,edge[u].len),t);if(!(flow-sum)) {depth[to]=0;break;}edge[u].len-=minn,edge[u^1].len+=minn,sum+=minn;}}return sum; }int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){//scanf("%d",&n);n=get_int(),m=get_int(),s=get_int(),t=get_int();for(int i=1;i<=m;i++){int x=get_int(),y=get_int(),low=get_int(),up=get_int();in[y]+=low,out[x]+=low,build(x,y,up-low),build(y,x,0);}tot=size;build(t,s,inf),build(s,t,0);pre();while(bfs(S,T)){memcpy(tmp,first,sizeof(first));ans+=dinic(S,inf,T);}if(ans!=sum) {cout<<"please go home to sleep\n";return 0;}first[S]=first[T]=0,ans=0;while(bfs(s,t)){memcpy(tmp,first,sizeof(first));ans+=dinic(s,inf,t);}cout<<ans<<"\n";//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的青岛农业大学第九届ACM程序设计竞赛的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最长公共回文子串(Longest_Com
- 下一篇: Ehab Fails to Be Tha