Codeforces Round #269 (Div. 2)

时间:2023-03-09 03:23:49
Codeforces Round #269 (Div. 2)

A

题意:给出6根木棍,如果有4根相同,2根不同,则构成“bear”,如果剩余两个相同,则构成“elephant”

用一个数组分别储存各个数字出现的次数,再判断即可

注意hash[i]==5的时候,也算作bear,因为它也是满足了4根相同,2根不同

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
int hash[],a[]; int main(){
int i,j,ans=;
memset(hash,,sizeof(hash));
for(i=;i<;i++){
cin>>a[i];
hash[a[i]]++;
} int x=,y=;
for(i=;i<=;i++){
if(hash[i]){
if(hash[i]==||hash[i]==||hash[i]==) x=;
if(hash[i]==||hash[i]==) y=;
}
} if(x&&y) printf("Elephant\n");
else if(x==&&y!=) printf("Bear\n");
else printf("Alien\n");
}

B

题意:给出n个数,按照从小到大的难度级别排序,问是否存在3种及三种以上这样的排序序列

这一题自己没想出来,想得还很复杂= =觉得好乱= = 不过后来看了题解,

发现这样就可以了,再用另一个b数组记录下来相同的数的位置,如果b数组的大小小于等于1,一定不满足

反之,只要b数组里面有两个数,我们就可以通过交换这两个位置(本身排出来有一个序列,分别交换两个位置可以得到两个),得到3个排序序列

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int maxn=+;
int b[maxn]; struct node{
int h;
int pos;
} a[maxn]; int cmp(node n1,node n2){
if(n1.h!=n2.h) return n1.h<n2.h;
return n1.pos<n2.pos;
} int main(){
int n,i,j,cnt;
cin>>n;
for(i=;i<=n;i++){
cin>>a[i].h;
a[i].pos=i;
} sort(a+,a+n+,cmp);
cnt=; for(i=;i<=n;i++){
if(a[i].h==a[i-].h){
b[cnt++]=i-;
}
}
if(cnt<=) printf("NO\n");
else{
printf("YES\n");
for(i=;i<n;i++)
printf("%d ",a[i].pos);
printf("%d\n",a[i].pos); swap(a[b[]],a[b[]+]); for(i=;i<n;i++)
printf("%d ",a[i].pos);
printf("%d\n",a[i].pos); // swap(a[b[0]],a[b[0]+1]);//这个地方叫交不交换都可以,交换了即为将第一个位置的换回来,都是不一样的序列
swap(a[b[]],a[b[]+]); for(i=;i<n;i++)
printf("%d ",a[i].pos);
printf("%d\n",a[i].pos);
}
return ;
}

C

题意:给出n个木棍,问能够搭成多少个不同高度的房子

首先想到的是算怎样消耗最少并且能够搭起最高的房子,

观察图可得:横杠之间有n个空隙,就会对应n+1个类似“八”的2根木棒,

Codeforces Round #269 (Div. 2)

这里的第几层是从最高层往最低层数 所以

第0层,0根横杠:1

第1层,1根横杠::1+(1+1)*2 -

第2层,2根横杠:2+(2+1)*2

第i层,i根横杠:i+(i+1)*2=3*i+2

即为满足这样的等差数列就可以消耗最小的房子

然后求前i项和:i*2+(i*(i-1))/2=i*(3*i+1)/2

然后就是自己的doubi思路:想的是,建成最高的了,然后就一层一层得往下拆,看可以拆成多少个高度不同的房子= =一直写不出来

正确的应该是这样:从i=1开始枚举,枚举到i*(3*i+1)/2<=n,这样即为完成消耗最小的房子,

又因为不能有木棒剩余,所以只能3根3根地加, 所以只需要满足n-(i*(3*i)+1)/2能够整除3即可

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
LL n;
LL ans,tmp,row,sum=; int main(){
cin>>n;
for(LL i=;(tmp=(*i+)*i/)<=n;i++){ if((n-tmp)%==)
ans++;
}
cout<<ans<<"\n";
return ;
}