暑假刷题第11天--7/22

Problem - E - Codeforces(二分)

#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
inline int read(){
	int d=0,f=1;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
	return d*f;
}
LL sqr(LL x){ 
    LL l = 1,r = 1e9; 
    while(l < r)
    { 
        LL mid = l + r + 1 >> 1; 
        if( mid * mid <= x) l = mid; 
        else r = mid - 1; 
    } 
    return l; 
}
void solve(){
	long long n,c;
	cin>>n>>c;
	long long sum=0;
	long long cnt=0;
	cnt-=c;
	for(int i=0;i<n;i++){
		int x=read();
		sum+=x;
		cnt+=x*x;
	}
	long long l=0,r=c/n;
	while(r>l){
		long long mid=(l+r)/2;
		if(n*mid==-cnt*1.0/(4*mid)-sum){
			cout<<mid<<endl;
			return;
		}
		else if(n*mid>-cnt*1.0/(4*mid)-sum){
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<l<<endl;
}
int main(){
    int t=read();
    
    while(t--){
    	solve();
	}
}

Problem - F - Codeforces(暴力)

#include<iostream>
#include<algorithm>
using namespace std;
const int N=200005;
int a[N];
int p[N];
void solve(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		p[i+1]=0;
	}
	sort(a,a+n);
	int sum=1;
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			sum++;
			continue;
		}
		else {
			for(int j=1;a[i]*j<=n;j++){
				p[a[i]*j]+=sum;
			}
			sum=1;
		}
	}

		for(int i=1;a[n-1]*i<=n;i++){
			p[a[n-1]*i]+=sum;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,p[i]);
	}
	cout<<ans<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

Problem - G - Codeforces

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N=200005;
int a[N];
int p[N];
void solve(){
	int n;
	map<int,int>ma,mj,mx,my;
	cin>>n;
	long long ans=0;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		ans+=2*(mx[x]+my[y]+ma[x+y]+mj[x-y]);
		mx[x]++;
		my[y]++;
		ma[x+y]++;
		mj[x-y]++;
	}
	cout<<ans<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

Problem - B - Codeforces

#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
using namespace std;
void solve(){
	int n;
	cin>>n;
	if(n==1)cout<<1<<endl;
	else if(n==2)cout<<2<<' '<<1<<endl;
	else {
		vector<int>ans(n+1);
		ans[(n+1)/2]=1;
		ans[1]=2;
		ans[n]=3;
		int t=3;
		for(int i=2;i<n;i++){
			if(i!=(n+1)/2){
				ans[i]=++t;
			}
		}
		for(int i=1;i<=n;i++){
			cout<<ans[i]<<' ';
		}
	}
	cout<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

Problem - C - Codeforces

#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
using namespace std;
void solve(){
	int n;
	cin>>n;
	long long sum1=0,sum2=0;
	long long ans=-1e9-6;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		ans=max((long long)ans,(long long)x);
		if(i%2==0&&x>0){
			sum1+=x;
		}
		else if(i%2==1&&x>0){
			sum2+=x;
		}
	}
	if(sum1!=0||sum2!=0)ans=max(ans,max(sum1,sum2));
	cout<<ans<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

Problem - D - Codeforces

#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
void solve(){
	int n;
	cin>>n;
	int p;
	string s;
	for(int i=1;i<=n+1;i++){
		if(n%i!=0){
			p=i;
			break;
		}
	}
	while(s.size()<=n){
		for(int i=0;i<p;i++){
			if(s.size()==n)break;
			s+=i%26+'a';
		}
		if(s.size()==n)break;
	}
	cout<<s<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

4737. 冰壶 - AcWing题库

#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int cnt=0;
double a[9],b[9];
void solve(){
	cnt++; 
	int rs,rh;
	cin>>rs>>rh;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[i]=sqrt(x*x*1.0+y*y*1.0);
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		b[i]=sqrt(x*x*1.0+y*y*1.0);
	}
	sort(a,a+n);
	sort(b,b+m);
	double k;
	if(m==0)k=200000;
	else k=b[0];
	int sum1=0,sum2=0;
	for(int i=0;i<n;i++){
		if(a[i]<=k&&(a[i]-rs<=rh)){
			sum1++;
		}
	}
	if(n==0)k=200000;
	else k=a[0];
	for(int i=0;i<m;i++){
		if(b[i]<=k&&(b[i]-rs<=rh)){
			sum2++;
		}
	}
	cout<<"Case #"<<cnt<<": "<<sum1<<" "<<sum2<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值