Đề thi HSG Môn Tin 11 Tỉnh Thanh Hóa – Năm học 2020 – 2021 – Kèm Code tham khảo
Đề thi HSG Môn Tin 11 Tỉnh Thanh Hóa – Năm học 2020 – 2021
Đề thi này chụp mờ quá bạn nào Word lại mình tặng code
Code tham khảo Đề thi HSG Môn Tin 11 Tỉnh Thanh Hóa – Năm học 2020 – 2021 viết bằng C++
Câu 1
[rml_read_more]
#include<bits/stdc++.h> using namespace std; int n,a[100001] ,c[100001] ,sum=0; long long res=0,x,y,z; string s; bool nt(int x) { for(int i=2;i<=sqrt(x);i++) if (x%i==0) return false; return true; } void test() { //srand(time(NULL)); int x=0; int y=x*9+1; x=(1000000000)-1; y=x; cout<<x<<' '<<y; } int main(){ //freopen("BAI1/23/BAI1.INP","w",stdout); //test(); //ios_base::sync_with_stdio(false); //cin.tie(nullptr); freopen("CAU1.INP","r",stdin); cin>>x>>y; z=__gcd(x,y); for(int i=1;i<=sqrt(z);i++) { if(z%i==0) { int t = z/i; res++; if (t!=i) res++; } } freopen("CAU1.OUT","w",stdout); cout<<res; return 0; }
Câu 2
#include<bits/stdc++.h> using namespace std; long long n,a[1000001] ,c[1000001] ,sum=0; long long res=0,x,y,z; string s; void test() { srand(time(NULL)); n=1000000; cout<<n<<endl; //cout<<"1 9 2 9 3 1 1 5"; for (int i=0;i<n;i++) cout<<(rand()%1000)*(rand()%1000)+1<<' '; //cout<<i+1<<' '; } int main(){ //freopen("BAI2/20/BAI2.INP","w",stdout); //test(); ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen("CAU2.INP","r",stdin); freopen("CAU2.OUT","w",stdout); cin>>n; for (int i=1;i<=n;i++) { cin>>x;a[x] ++; res=max(res,a[x] ); } cout<<res; return 0; }
Câu 3
#include<bits/stdc++.h> using namespace std; int n,a[100001] ,c[100001] ,sum=0; long long res=0; string s; void test() { srand(time(NULL)); int n=10000,j=0,jj=0; cout<<rand()%9+1; //cout<<4; //for (int i=1;i<=5000;i++) cout<<3; for (int i=1;i<=n-1;i++) cout<<rand()%2; //cout<<'3'; } void sub1() { res=(sum==0); for(int i=1;i<=n;i++) { int k=0; for(int j=i;j<=n;j++){ k=(k+a[j] )%3; if (sum==k) res++; } } res--; } long long tinh(int x,int y) { long long ans=0,k=0; for (int i=0;i<=n;i++){ if (c[i] ==x) ans+=k; if (c[i] ==y) k++; } return ans; } void sub2() { res=(sum==0); for(int i=1;i<=n;i++) c[i] =(c[i-1] +a[i] )%3; if (sum==0){res+=tinh(0,0)+tinh(1,1)+tinh(2,2);} if (sum==1){res+=tinh(1,0)+tinh(2,1)+tinh(0,2);} if(sum==2){res+=tinh(0,1)+tinh(1,2)+tinh(2,0);} res--; } const char* ff = "CAU3.INP"; const char* fo = "CAU3.OUT"; int main(){ //freopen(ff,"w",stdout); //test(); ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen(ff,"r",stdin); freopen(fo,"w",stdout); cin>>s;n=s.length(); //cout<<n; return 0; for (int i=0;i<s.length();i++) {a[i+1] =s[i] -48;sum=(sum+a[i+1] )%3;} //sub1(); //cout<<res; sub2(); cout<<res; return 0; }
Câu 4
#include<bits/stdc++.h> using namespace std; int n,a[100001] ,c[100001] ,sum=0; long long res=0; string s; void test() { srand(time(NULL)); int n=1000000,j=0,jj=0; //cout<<'b'; for(int i=0;i<n;i++) cout<< (char)(rand()%26+97); //cout<<'a'; //cout<<'c'; } bool nguyen_am(char ch){ return (ch=='a'||ch=='e'||ch=='i'||ch=='o' ||ch=='u'); } const char* ff = "CAU4.INP"; const char* fo = "CAU4.OUT"; int main(){ //freopen(ff,"w",stdout); //test(); ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen(ff,"r",stdin); freopen(fo,"w",stdout); cin>>s; n=s.length(); long long pa=0, na=0; for (int i=0;i<n;i++) { if (nguyen_am(s[i] )) { res+=pa;na++; } else{ res+=na; pa++; } } cout<<res; return 0; }
Câu 5
#include <bits/stdc++.h> using namespace std; long long Rnhon , Rvuong, Rtu ; long long n; long long a[5005] ; int b[10001] ={0}; bool nhon(int x, int y, int z){ return z*z<x*x+y*y; } bool vuong(int x, int y, int z){ return z*z==x*x+y*y; } bool tu(int x, int y, int z){ return z*z>x*x+y*y; } bool tam_giac(int x, int y, int z){ return z<x+y; } void sub1() { for(int i=1;i<=n-2;i++) for(int j=i+1;j<=n-1;j++) for(int k=j+1;k<=n;k++) if (tam_giac(a[i] ,a[j] ,a[k] )) { if (nhon(a[i] ,a[j] ,a[k] )) Rnhon++; if (vuong(a[i] ,a[j] ,a[k] )) Rvuong++; if (tu(a[i] ,a[j] ,a[k] )) Rtu++; } cout<<Rnhon<<' '<<Rvuong<<' '<<Rtu; } void sub2() { Rnhon= Rvuong =Rtu=0; long long R=0; int k=3; for(int i=1;i<=n-2;i++){ k=i+2; for(int j=i+1;j<=n-1;j++) { if (k<=j) k=j+1; while (k<=n && a[k] <a[i] +a[j] ) k++; R+= (k-j-1); } } for(int i=1;i<=n-2;i++){ k=i+2; for(int j=i+1;j<=n-1;j++) { if (k<=j) k=j+1; while (k<=n && a[k] *a[k] <a[i] *a[i] +a[j] *a[j] ) k++; if (vuong(a[i] ,a[j] ,a[k] )) Rvuong++; Rnhon+= (k-j-1); } } cout<<Rnhon<<' '<<Rvuong<<' '<<R-Rvuong-Rnhon; } //const char* ff = "BAI5/7/BAI5.INP"; //const char* fo = "BAI5/7/BAI5.OUT"; const char* ff = "CAU5.INP"; const char* fo = "CAU5.OUT"; void test() { freopen(ff,"w",stdout); srand(time(NULL)); n=5000; cout<<n<<endl; int j=0; for (int i=1;i<=n;i++) { do{ j=rand()%6000+1; } while(b[j] ); b[j] =1; cout<<n-i+1<<' '; } } int main(){ //test(); ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen(ff,"r",stdin); freopen(fo,"w",stdout); cin>>n; for(int i=1;i<=n;i++) cin>>a[i] ; sort(a+1,a+n+1); //sub1(); //cout<<endl; sub2(); }