2019-12-2回收站选址
这个写的时候感觉如果定义一个二维数组那也太大了吧,而且要遍历的话也很麻烦。看到别人写的用了map和set感觉好方便呀,大概就是把node和bool作为一个单元。根据node的x,y来判断其得分,bool值表明是否有垃圾!应该就是看很大规模的数据怎么处理吧。具体代码:
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
struct node{
int x;
int y;
node(){
}
node(int a,int b){
x=a;
y=b;
}
bool operator<(const node th)const{
if(x!=th.x)return x<th.x;
return y<th.y;
}
}h[10000];
map<node,bool> mymap;
int c[6];
int main(){
int n,x,y;
cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
h[i]=node(x,y);
mymap[h[i]]=1;
}
for(int i=0;i<n;i++){
int cnt=0;
x=h[i].x;
y=h[i].y ;
if(mymap[node(x+1,y)]&&mymap[node(x-1,y)]&&mymap[node(x,y+1)]&&mymap[node(x,y-1)]){
cnt=mymap[node(x-1,y-1)]+mymap[node(x+1,y+1)]+mymap[node(x-1,y+1)]+mymap[node(x+1,y-1)];
c[cnt]++;
}
}
for(int i=0;i<5;i++){
cout<<c[i]<<endl;
}
}
2019-9-2
这个题应该是怎么判断三棵连着的树是不是都掉了⑧。(n+I+1)%n
#include<iostream>
using namespace std;
int c[1005];
int main(){
int n,m,temp,count,sum=0,drop=0,dd=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>m;
cin>>temp;
count=temp;
// cout<<"$$$$$$$$"<<count<<endl;
for(int j=1;j<m;j++){
cin>>temp;
if(temp>0){
if(count!=temp){
c[i]=1;
count=temp;
}
continue;
}
count+=temp;
}
// cout<<"$$$$$$$$"<<count<<endl;
sum+=count;
}
for(int i=0;i<n;i++){
if(c[i]==1){
//cout<<"******"<<i<<endl;
drop++;
if(c[(n+i+1)%n]&&c[(n+i-1)%n]){
dd++;
}
}
}
cout<<sum<<' '<<drop<<' '<<dd<<endl;
}