湖南大学第十五届程序设计竞赛
Problem A?Oshino Shinobu loves Mr.Donut
https://ac.nowcoder.com/acm/contest/908/A
題意:
題解:
C++版本一
?
Problem B?Kuangyeye's Resistance
https://ac.nowcoder.com/acm/contest/908/B
題意:計算n級網(wǎng)絡的等效電阻。
題解:
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; ll t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum; int a[N]; char str; struct node{}; ll POW(ll a,ll b=p-2,ll c=p){ll res=1;ll base=a%c;while(b){if(b&1)res=(res*base)%p;base=(base*base)%p;b>>=1;}return res; } 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("%lld%lld%lld",&n,&r,&p);ll R=r;for(int i=2;i<=n;i++){R=(((R+2*r)%p*r%p)*((POW(R+3*r,p-2,p))%p))%p;}cout<<R<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem C?One Piece
https://ac.nowcoder.com/acm/contest/908/C
題意:二進制表示中找到1的數(shù)。
題解:__builtin_popcount
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);printf("%d\n",__builtin_popcount(n));}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem D?Kth height
https://ac.nowcoder.com/acm/contest/908/D
題意:兩只球隊,都是n個人且都身高遞增,m次操作,將p隊的第q個人的身高變?yōu)閠,并詢問兩只球隊總集合中第k矮的那個人的身高,保證修改之后依然遞增
題解:二分
C++版本一
題解:二分
1、二分出前k個人,在第一隊里面有多少個;
2、注意多組數(shù)據(jù);
3、二分范圍[0,k];
/* *@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,q; int ans,cnt,flag,temp,sum; int a[3][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--){while(~scanf("%d",&n)){for(int i=1;i<=n;i++)scanf("%d",&a[1][i]);for(int i=1;i<=n;i++)scanf("%d",&a[2][i]);scanf("%d",&m);for(int i=1;i<=m;i++){scanf("%d%d%d%d",&p,&q,&t,&k);a[p][q]=t;l=0;r=k;while(l<=r){int mid=(l+r)>>1;int temp=(upper_bound(a[2]+1,a[2]+n+1,a[1][mid])-a[2])-1;if(mid+temp<=k){ans=mid;l=mid+1;}else{r=mid-1;}}cout<<max(a[1][ans],a[2][k-ans])<<endl;}}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem E?Just calculat
https://ac.nowcoder.com/acm/contest/908/E
題意:
題解:
C++版本一
?
Problem F?Cards with Numbers
https://ac.nowcoder.com/acm/contest/908/F
題意:
兩個操作:
- 0 x(? 表示在包裝盒中放入帶有數(shù)字x的卡片。)
- 1 x(? 表示查詢在包裝盒中是否有號碼為x的卡片。)
題解:
1、字典樹
2、離散化+離線處理
C++版本一
題解:字典樹
注意:數(shù)據(jù)原因可能還沒最糟糕的情況所以卡過
/* *@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=2500000+10; const int M=1000+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,op; int ans,cnt,flag,temp; int a[N][10]; int en[N]; char x[20]; void insert(char *s){int len=strlen(s),p=0;for(int i=0;i<len;i++){int ch=s[i]-'0';if(a[p][ch]==-1)a[p][ch]=++cnt;p=a[p][ch];}en[p]=1; } bool search(char* s){int len=strlen(s),p=0;for(int i=0;i<len;i++){int ch=s[i]-'0';if(a[p][ch]==-1)return 0;p=a[p][ch];}return en[p]; } 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);memset(a,-1,sizeof(a));for(int i=1;i<=n;i++){scanf("%d%s",&op,x);if(!op){insert(x);}else{cout<<(search(x)?"yes":"no")<<endl;}}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }C++版本二
題解:?離散化+離線處理
Problem G?Longest Palindrome Substring
https://ac.nowcoder.com/acm/contest/908/G
題意:最長的回文子串的長度是否大于1
題解:枚舉
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[N]; 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);cin>>str;for(int i=1;i<n-1;i++){if(str[i-1]==str[i+1]||str[i-1]==str[i]||str[i]==str[i+1]){ans=1;break;}}cout<<(ans||(n==2&&str[0]==str[1])?"YES":"NO")<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem H?Longest Common Palindrome Substring
https://ac.nowcoder.com/acm/contest/908/H
題意:
題解:
C++版本一
?
Problem I?Algorithm Choosing Mushrooms
https://ac.nowcoder.com/acm/contest/908/I
題意:給你n個籃子以及籃子里有的蘑菇,你可以取走一段連續(xù)的籃子,但這些籃子里的蘑菇總和必須是m的倍數(shù),問你最多拿幾只籃子?最多拿多少蘑菇?
題解:DP
C++版本一
題解:DP
1、記錄每個余數(shù)第一次出現(xiàn)的位置;
2、余數(shù)再次出現(xiàn),則以當前數(shù)為結(jié)尾的最長區(qū)間【第一次位置,當前位置】;
/* *@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=200000+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; ll ans,cnt,flag,temp,sum; ll a[N]; ll b[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,&m);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);a[i]+=a[i-1];temp=a[i]%m;if(b[temp]==0)b[temp]=i;if((a[i]-a[b[temp]])%m==0){ans=max(ans,i-b[temp]);sum=max(sum,a[i]-a[b[temp]]);}}cout<<sum<<" "<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }Problem J?Simple Problem
https://ac.nowcoder.com/acm/contest/908/J
題意:
題解:
C++版本一
?
Problem K?Water Problem
https://ac.nowcoder.com/acm/contest/908/K
題意:
題解:
C++版本一
?
總結(jié)
以上是生活随笔為你收集整理的湖南大学第十五届程序设计竞赛的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ACM/OI中C++常用优化(实用/调试
- 下一篇: 最长公共回文子串(Longest_Com