AtCoder Beginner Contest 234 题解

A、

题意明了不用思考直接模拟

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
LL cul(LL x)
{
	return x*x+2*x+3;
}
int main()
{
	LL n;
	scanf ("%lld",&n);
	printf ("%lld",cul(cul(cul(n)+n)+cul(cul(n))));
    return 0;
}

B、

给出一组点求里面最远的两个点的距离,暴力。

#include<iostream>
#include<algorithm>
#include<cstring>
#include <cmath>
#define x first
#define y second
using namespace std;
typedef pair<double,double> PII;
PII a[110];
int main()
{
	int n;
	scanf ("%d",&n);
	for (int i=0;i<n;i++)
	{
		double c,d;
		scanf ("%lf %lf",&c,&d);
		a[i] = {c,d};
	}
	double res = 0.0;
	for (int i=0;i<n;i++)
	{
		for (int j=i+1;j<n;j++)
		{
			double t = (a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
			if (t>res)
			res = t;
		}
	}
	printf ("%lf",sqrt(res));
    return 0;
}

C、

在以10为基数的由0和2组成的正整数中,找出第k小的整数。
我真傻屌,刚开始以为有递归树结构,直接去dfs了,后来发现就是考察二进制的题把01换成02。。。

#include<iostream>
#include<algorithm>
#include<cstring>
#include <cmath>
using namespace std;
bool st[100];
int main()
{
    memset(st,0,sizeof st);
	long long n;
	scanf ("%lld",&n);
    string s;
    int k=0;
     while (n)
     {
     	if (n&1) st[k] = true;
     	n>>=1;
     	k++;
	 }
	 for (int i=k-1;i>=0;i--)
	 {
	 	if (st[i])
	 	   s+='2';
	 	   else
	 	   s+='0';  
	 }
//	 while (s[0]=='0')s.erase(0);
	cout<<s<<endl;
    return 0;
}

D、

给一个排列,让求从前k个数的第k大数、前k+1个数的第k大数…到前n个数的第k大数。一看数据范围只能nlogn才能过,想想已知数据结构用优先队列

#include<iostream>
#include<algorithm>
#include<cstring>
#include <cmath>
#include<queue>
using namespace std;
const int N =5e5+10;
int a[N];
int main()
{
	priority_queue<int,vector<int>,greater<int> >mh;
	int n,k;
	scanf ("%d%d",&n,&k);
	for (int i=0;i<n;i++)
		scanf ("%d",&a[i]);
    for (int i=0;i<k;i++) mh.push(a[i]);
    cout<<mh.top()<<endl;
    for (int i=k;i<n;i++)
    {
    	if (a[i]>mh.top())
    	{
    		mh.pop();
    		mh.push(a[i]);
    		cout<<mh.top()<<endl;
		}
		else
		cout<<mh.top()<<endl;
	}
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值