AtCoder Beginner Contest 159 A~~D

A.
水题

#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	if(n<=1&&m<=1){
		cout<<"0"<<endl;
	}else{
		
	
	int res = n*(n-1)/2;
	int ans = m*(m-1)/2;
	cout<<res+ans<<endl;
}
	return 0;
} 

B
水题

#include<bits/stdc++.h>

using namespace std;
int l;
bool judge( string & s){
	string temp = s;
	reverse(temp.begin(),temp.end());
	return temp == s;
}

int main(){
	string ss;
	cin>>ss;
	string a="";
	string b="";
	l = ss.length();
	for(int i=0;i<(l-1)/2;i++){
		a+=ss[i];
	}
	for(int i=(l+3)/2-1;i<l;i++){
		b+=ss[i];
	}
	if(judge(ss)){
	   if(judge(a)&&judge(b)){
	   	cout<<"Yes"<<endl;
	   }
	   else{
	   	cout<<"No"<<endl;
	   }
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
} 

C
水题

#include<bits/stdc++.h>

using namespace std;

int main(){
	double n;
	cin>>n;
    
		printf("%.12lf",(n/3)*(n/3)*(n/3));
	
	
	return 0;
}

D
暴力会超时。
TL代码~

#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int a[maxn];
int num[maxn]={0};

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		num[a[i]]++;
	}
	int ans;
	for(int i=1;i<=n;i++){
		num[a[i]]--;
		ans = 0;
		for(int i=1;i<maxn;i++){
			if(num[i]>=2){
				ans += num[i]*(num[i]-1)/2;
			}
		}
		cout<<ans<<endl;
		num[a[i]]++;
	}
	return 0;
} 

大佬AC代码

#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long ll;
map<ll,ll> mp;
ll a[maxn];
vector<ll> v;

int main(){
	int n;
	cin >>n;
	ll sum=0,ans=0;
	for(int i=0;i<n;i++) cin >>a[i],mp[a[i]]++;
	for(auto x : mp){
		ll res=x.second;
		if(res>=2) sum+=res*(res-1)/2,v.push_back(res);
	}
	for(int i=0;i<n;i++){
		ll x=a[i];
		if(mp[x]>=2){
			ll res=mp[x];
			cout <<sum-res*(res-1)/2+(res-1)*(res-2)/2<<endl;
		}
		else 
		cout <<sum<<endl;
	}
}
全部评论

相关推荐

07-22 11:12
门头沟学院 Java
不是,我就随手投的怎么还真发面试啊
皮格吉:大厂特别快的——来自已经被共享中
点赞 评论 收藏
分享
allin秋招的单身...:我投过这家 上来就发个设计图给我,让我做好发到他邮箱
点赞 评论 收藏
分享
zzzzhz:兄弟你先猛猛投简历至少三百家,能约到面试就去面。最近可以速成智能小车,智慧家居烂大街的项目,不需要自己写,只需要把里面的代码讲解看明白就行。把其中涉及到的八股文都拿出来单独背一下,我去年找工作就一个智能小车智慧家居找了10k差不多。
点赞 评论 收藏
分享
今天 10:31
门头沟学院 Java
求问各位大佬,笔试都考点啥
投递科大讯飞等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务