root

363

14天前
#include<iostream>
#include<cmath>
using namespace std;
int main(){
double n;
cin>>n;
double mid;
double l=-10000,r=10000;
while(r-l>=1e-8){
mid=(l+r)/2;
if((mid*mid*mid)>=n) r=mid;
else l=mid;
}
printf("%lf",l);

return 0;
}

14天前
#include<iostream>
#include<cmath>
using namespace std;
int main(){
double n;
cin>>n;
double mid;
double l=-10000,r=10000;
while(r-l>=1e-8){
mid=(l+r)/2;
if((mid*mid*mid)>=n) r=mid;
else l=mid;
}
printf("%lf",l);

return 0;
}

14天前
#include<iostream>
using namespace std;
const int N=100010;
int n,m;
int q[N];
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%d",&q[i]);
while(m--){
int x;
scanf("%d",&x);
int l=0,r=n-1;
while(l<r){
int mid=l+r>>1;
if(q[mid]>=x) r=mid;
else l=mid+1;
}
if(q[l]!=x) cout<<"-1 -1"<<endl;
else{
cout<<l<<" ";
int l=0,r=n-1;
while(l<r){
int mid=l+r+1>>1;
if(q[mid]<=x) l=mid;
else r=mid-1;
}
cout<<l<<endl;
}
}
return 0;
}

15天前
#include<iostream>
using namespace std;
const int N=100010;
int n;
long long ans;
int q[N],temp[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]) temp[k++]=q[i++];
else{
ans+=mid-i+1;//统筹不满足的情况
temp[k++]=q[j++];
}
}
while(i<=mid) temp[k++]=q[i++];
while(j<=r) {
temp[k++]=q[j++];
}
for(int i=l,j=0;i<=r;j++,i++) q[i]=temp[j];
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&q[i]);
merge_sort(q,0,n-1);
cout<<ans<<endl;
return 0;
}

15天前
#include<iostream>
using namespace std;
const int N=100010;
int n;
int q[N],temp[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 i=l,j=mid+1,k=0;
while(i<=mid&&j<=r){
if(q[i]<=q[j]) temp[k++]=q[i++];
else temp[k++]=q[j++];
}
while(i<=mid) temp[k++]=q[i++];
while(j<=r) temp[k++]=q[j++];
for(int i=l,j=0;i<=r;i++,j++){
q[i]=temp[j];
}
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&q[i]);
merge_sort(q,0,n-1);
for(int i=0;i<n;i++) printf("%d ",q[i]);
return 0;
}

15天前
#include<iostream>
using namespace std;
const int N=100010;
int n,k;
int q[N];
void quick_sort(int q[],int l,int r){
if(l>=r) return;
int x=q[(l+r)>>1];
int i=l-1,j=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(){
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",&q[i]);
quick_sort(q,0,n-1);
printf("%d",q[k-1]);
}

15天前
#include<iostream>
using namespace std;
const int N=100010;
int n,q[N];
void quick_sort(int q[],int l,int r){
if(l>=r)return;
int i=l-1,j=r+1;
int mid=(l+r)>>1;
int 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(){
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;
}

16天前