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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

吉首大学2019年程序设计竞赛

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

Problem A?SARS病毒

https://ac.nowcoder.com/acm/contest/992/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; ll ans,cnt,flag,temp,sum; ll a[4][4],b[4][4]; char str[N]; struct node{}; void Matrix(ll a[4][4],ll b[4][4]){ll e[4][4];memset(e,0,sizeof(e));for(int i=0;i<4;i++){for(int j=0;j<=i;j++){for(int k=0;k<4;k++){e[j][i]=e[i][j]=(e[i][j]+a[i][k]*b[k][j])%MOD;}}}for(int i=0;i<4;i++){for(int j=0;j<4;j++){a[i][j]=e[i][j];}} } ll power(int k){for(int i=0;i<4;i++){for(int j=0;j<4;j++){if(i==j)a[i][j]=1,b[i][j]=2;else if(i+j==3) a[i][j]=0,b[i][j]=0;else a[i][j]=0,b[i][j]=1;}}while(k){if(k&1)Matrix(a,b);Matrix(b,b);k>>=1;}return a[0][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(~scanf("%s",str)){int len=strlen(str);temp=0;for(int i=0;i<len;i++){temp=(temp*10+str[i]-'0')%(MOD-1);}cout<<power(temp)<<endl;}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }

C++版本二

題解:費馬小定理+快速冪+數學

#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll p=1e9+7; string str; ll qmi(ll a,ll b) {ll res=1;while(b){if(b&1) res=res*a%p;b>>=1;a=a*a%p;}return res; } int main() {while(cin>>str){ll k=0;for(int i=0;i<str.size();i++) k=(k*10+str[i]-'0')%(p-1);cout<<(qmi(2,k-1)+qmi(4,k-1))%p<<endl;}return 0; }

?

Problem B?干物妹小埋

https://ac.nowcoder.com/acm/contest/992/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=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; ll ans,cnt,flag,temp,sum; int a[N],h[N],v[N],A[N]; char str; struct node{}; ll tree[N]; void update(int x,ll val){while(x<=cnt){tree[x]=max(tree[x],val);x+=x&-x;} } ll query(int x){ll res=0;while(x){res=max(tree[x],res);x-=x&-x;}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("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]),h[i]=a[i];sort(a+1,a+n+1);A[++cnt]=a[1];for(int i=2;i<=n;i++)if(a[i]!=a[i-1])A[++cnt]=a[i];for(int i=1;i<=n;i++){scanf("%d",&v[i]);ll id = lower_bound(A+1,A+cnt+1,h[i])-A;temp = query(id);ans = max(ans, temp + v[i]);update(id, temp + v[i]);}cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }

Problem C?

?

題意:

題解:

C++版本一

?

Problem D?

?

題意:

題解:

C++版本一

?

Problem E?多喝嚶料

https://ac.nowcoder.com/acm/contest/992/E

題意:

題解:

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; ll 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);ans=m=n;while(n/3||m/4){temp=n/3+m/4;n%=3;m%=4;n+=temp;m+=temp;ans+=temp;}cout<<ans<<endl;}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }

Problem F?天花亂墜

https://ac.nowcoder.com/acm/contest/992/F

題意:

題解:計算幾何+極限+等比數列求和

已知正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; double 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(~scanf("%d",&n)){printf("%.2f\n",(100*n)/(1-cos(PI/n)));}#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/992/G

題意:

題解:

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; ll ans,cnt,flag,temp,sum,cot; char ch[100007]; 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("%s",ch);int len=strlen(ch);for(int i=0;i<len;i++)if(ch[i]=='Z')cnt++;for(int i=0;i<len;i++){if(ch[i]=='O')cot++;if(ch[i]=='R')ans+=cot*cnt;if(ch[i]=='Z')cnt--;}printf("%lld\n",ans);//}#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/992/H

題意:

題解:

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=1000+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; char a[N][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(~scanf("%d",&n)){int pos=0;for(int i=1;i<=2*n+1;i++){if(i&1)for(int j=1;j<=2*n+1;j++){a[i][j]=pos+'a';pos++;pos%=26;}elsefor(int j=2*n+1;j>=1;j--){a[i][j]=pos+'a';pos++;pos%=26;}}for(int i=1;i<=2*n+1;i++){for(int j=1;j<=2*n+1;j++)printf("%c",a[i][j]);cout<<endl;}}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }

Problem I?滑稽樹上滑稽果

https://ac.nowcoder.com/acm/contest/992/I

題意:求

題解:組合數學+預處理+逆元+莫隊算法+分塊

易得:

C++版本一

?

Problem J?

?

題意:

題解:

C++版本一

?

Problem K?

?

題意:

題解:

C++版本一

?

總結

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

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