HXER233

1625

HXER233
2天前

MBT

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int tmp[N],a[N];
void merge_sort(int q[], int l, int r)  // 归并排序
{
if (l >= r) return;

int mid = l + r >> 1;
merge_sort(q, l, mid);
merge_sort(q, mid + 1, r);

int k = 0, i = l, j = mid + 1;
while (i <= mid && j <= r)
if (q[i] <= q[j]) tmp[k ++ ] = q[i ++ ];
else tmp[k ++ ] = q[j ++ ];

while (i <= mid) tmp[k ++ ] = q[i ++ ];
while (j <= r) tmp[k ++ ] = q[j ++ ];

for (i = l, j = 0; i <= r; i ++, j ++ ) q[i] = tmp[j];
}

int main(){
int n;
scanf("%d", &n);
for (int i = 0; i < n; i ++ )scanf("%d", &a[i]);
merge_sort(a,0,n-1);
for (int i = 0; i < n; i ++ )printf("%d ", a[i]);
return 0;
}

HXER233
3天前

AH

#include <bits/stdc++.h>
using namespace std;

vector<int> div(vector<int> &A, int b, int &r){
vector<int> C;
r = 0;
for(int i = A.size() - 1; i >= 0; i --){
r = r * 10 + A[i];
C.push_back(r / b);
r %= b;
}

reverse(C.begin(), C.end());
while(C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}

int main(){
string a;
int b;
cin >> a >> b;
vector<int> A;
for(int i = a.size() - 1; i >= 0; i --) A.push_back(a[i] - '0');

int r;
auto C = div(A, b, r);
for(int i = C.size() - 1; i >= 0; i --) printf("%d", C[i]);
cout << endl << r << endl;
return 0;
}

HXER233
4天前

EC

#include <bits/stdc++.h>
using namespace std;
int main(){
string a,b;
cin>>a>>b;
int la=a.size(),lb=b.size(),w=0;
vector<int> sa;vector<int> sb;vector<int> ans(la+lb,0);
for(int i=la-1;i>=0;i--)sa.push_back(a[i]-'0');
for(int i=lb-1;i>=0;i--)sb.push_back(b[i]-'0');
for(int i=0;i<la;i++)for(int j=0;j<lb;j++)ans[i+j]+=sa[i]*sb[j];
for(int i=0;i<la+lb;i++)w+=ans[i],ans[i]=w%10,w/=10;
while(ans.size()>1&&ans.back()==0)ans.pop_back();
for(int i=ans.size()-1;i>=0;i--)cout<<ans[i];
return 0;
}

HXER233
4天前

EC

#include <bits/stdc++.h>
using namespace std;
string a,b;
int main(){
cin>>a>>b;
if(a.size()<b.size()||a.size()==b.size()&&a<b){cout<<'-';a.swap(b);}
int la=a.size(),lb=b.size(),sa[max(la,lb)],sb[max(la,lb)],w=0;memset(sb,0,sizeof sb);
for(int i=0;i<la;i++)sa[i]=a[la-i-1]-'0';
for(int i=0;i<lb;i++)sb[i]=b[lb-i-1]-'0';
for(int i=0;i<la;i++){sa[i]=sa[i]-sb[i]-w,w=0;if(sa[i]<0)w=1,sa[i]+=10;}
for(int i=la-1;i>=0;i--){if(sa[i]==0&&la>1)la--;else break;}
for(int i=la-1;i>=0;i--)cout<<sa[i];
return 0;
}

HXER233
4天前

EC

#include <bits/stdc++.h>
using namespace std;
string a,b;
int main(){
cin>>a>>b;
long long la=a.size(),lb=b.size(),sa[100010],sb[100010],w=0;
for(long long i=0;i<la;i++)sa[i]=a[la-i-1]-'0';
for(long long i=0;i<lb;i++)sb[i]=b[lb-i-1]-'0';
for(long long i=0;i<max(la,lb);i++)sa[i]=sa[i]+sb[i]+w,w=sa[i]/10,sa[i]%=10;
if(w==1)cout<<w;
for(long long i=max(la,lb)-1;i>=0;i--)cout<<sa[i];
return 0;
}

HXER233
5天前

sortNB

#include <bits/stdc++.h>
using namespace std;
int n,k,ans;
int main(){
cin>>n>>k;
int sum[n];
for(int i=0;i<n;i++)cin>>sum[i];
sort(sum,sum+n);
cout<<sum[k-1];
return 0;
}

qsort

#include <bits/stdc++.h>
using namespace std;
void qsort(int q[],int l,int r){
if(l>=r)return;
int i=l-1,j=r+1,x=q[l+r>>1];
while(i<j){
do i++;while(q[i]<x);
do j--;while(q[j]>x);
if(i<j)swap(q[i],q[j]);
}
qsort(q,l,j);
qsort(q,j+1,r);
}
int main(){
int q[100010],n,k;
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++)scanf("%d",&q[i]);
qsort(q,0,n-1);
printf("%d",q[k-1]);
return 0;
}

HXER233
5天前

YXC模板

#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int q[N];
void quick_sort(int q[], int l, int r){
if(l>=r)return;
int i=l-1,j=r+1,x=q[l+r>>1];
while (i<j){
do i++;while(q[i]<x);
do j--;while (q[j]>x);
if(i<j)swap(q[i],q[j]);
}
quick_sort(q,l,j),quick_sort(q,j+1,r);
}
int main(){
int n;
scanf("%d",&n);
for (int i=0;i<n;i++)scanf("%d",&q[i]);
quick_sort(q,0,n-1);
for (int i=0;i<n;i++)printf("%d ",q[i]);
return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
for(int q=0;q<n;q++)cout<<a[q]<<" ";
return 0;
}

HXER233
7天前

题目描述

5 3

2

C++ 代码

#include <bits/stdc++.h>
using namespace std;
string n;
long long m,ans=0,l;
signed main(){
cin>>n>>m;
l=n.size();
for(int i=0;i<l;i++)ans=(ans*10+n[i]-'0')%m;
cout<<ans;
}

HXER233
30天前

EC

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll x,y,z,ans=0;
ll qp(ll a,ll b,ll m){
while(b){
if(b&1)ans=(ans+a)%m;
a=a*2%m,b>>=1;
}
return ans%m;
}
int main(){
cin>>x>>y>>z;
cout<<qp(x,y,z);
return 0;
}

HXER233
30天前

EC

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll x,y,z,ans=1;
ll qp(ll a,ll b,ll m){
while(b){
if(b&1)ans=ans*a%m;
a=a*a%m,b>>=1;
}
return ans%m;
}
int main(){
cin>>x>>y>>z;
cout<<qp(x,y,z);
return 0;
}