日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

湖南大学第十五届程序设计竞赛

發布時間:2024/10/5 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 湖南大学第十五届程序设计竞赛 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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級網絡的等效電阻。

題解:

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的數。

題解:__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個人的身高變為t,并詢問兩只球隊總集合中第k矮的那個人的身高,保證修改之后依然遞增

題解:二分

C++版本一

題解:二分

1、二分出前k個人,在第一隊里面有多少個;

2、注意多組數據;

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(? 表示在包裝盒中放入帶有數字x的卡片。)
  • 1 x(? 表示查詢在包裝盒中是否有號碼為x的卡片。)

題解:

1、字典樹

2、離散化+離線處理

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=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個籃子以及籃子里有的蘑菇,你可以取走一段連續的籃子,但這些籃子里的蘑菇總和必須是m的倍數,問你最多拿幾只籃子?最多拿多少蘑菇?

題解:DP

C++版本一

題解:DP

1、記錄每個余數第一次出現的位置;

2、余數再次出現,則以當前數為結尾的最長區間【第一次位置,當前位置】;

/* *@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++版本一

?

總結

以上是生活随笔為你收集整理的湖南大学第十五届程序设计竞赛的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。