ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AtCoder Beginner Contest 234 题解

2022-01-08 22:02:17  阅读:132  来源: 互联网

标签:AtCoder cul int 题解 scanf st main 234 include


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;
}

标签:AtCoder,cul,int,题解,scanf,st,main,234,include
来源: https://blog.csdn.net/MH3709/article/details/122387240

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有