题目链接:https://www.jisuanke.com/contest/731
①微软手机的信号显示
题目描述
微软近日推出了一款功能极简的手机,在手机上用一个包含了
7×7个像素的区域来显示手机信号。满信号的时候显示如下:
+-----+
|- 4G|
|-- |
|--- |
|---- |
|-----|
+-----+
每一格信号( 第 i(1 ≤ i ≤ 5)格信号有 i 个 ‘-’ )代表 20% 的信号强度,不足一格信号的部分不显示。同时会在右上角显示当前的网络传输模式。在信号强度不低于 90% 的时候显示4G;当信号低于 90%、不低于 60% 的时候显示3G;否则显示E。对于给定的当前信号强度 d%,输出信号的 7×7 像素的图案。
输入格式
输入一个整数 d(0≤d≤100),表示信号强度。
输出格式
按照题目要求输出,每行末尾不要输出多余的空白字符。
样例输入1
0
样例输出1
+-----+
| E|
| |
| |
| |
| |
+-----+
样例输入2
65
样例输出2
+-----+
|- 3G|
|-- |
|--- |
| |
| |
+-----+
这题比较简单,只要按照题目说得来就行,不过我做的时候还是错了好几次。。。
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int pow;
cin>>pow;
cout<<"+-----+"<<endl;
cout<<"|";
if(pow<20)
{
cout<<" E|"<<endl;
}
else if(pow<60)
{
cout<<"- E|"<<endl;
}
else if(pow<90)
cout<<"- 3G|"<<endl;
else
{
cout<<"- 4G|"<<endl;
}
if(pow<40)
{
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
}
else if(pow<60)
{
cout<<"|-- |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
}
else if(pow<80)
{
cout<<"|-- |"<<endl;
cout<<"|--- |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
}
else if(pow<100)
{
cout<<"|-- |"<<endl;
cout<<"|--- |"<<endl;
cout<<"|---- |"<<endl;
cout<<"| |"<<endl;
}
else
{
cout<<"|-- |"<<endl;
cout<<"|--- |"<<endl;
cout<<"|---- |"<<endl;
cout<<"|-----|"<<endl;
}
cout<<"+-----+"<<endl;
return 0;
}
②微软大楼的设计方案(简单)(原题有图,可以从文章顶部的题目链接点进去看)
题目描述
近日,微软新大楼的设计方案正在广泛征集中,其中一种方案格外引人注目。在这个方案中,大楼由 n 栋楼组成,这些楼从左至右连成一排,编号依次为 1 到 n,其中第 i 栋楼有 hi 层。每栋楼的每一层为一个独立的 办公区域,可以步行 直达同层相邻楼栋的办公区域,以及 直达同楼栋相邻楼层的办公区域。
由于方案设计巧妙,上一层楼、下一层楼、向左右移动到相邻楼栋同层的办公区域均刚好需要 1 分钟。在这些办公区域中,有一些被 核心部门 占用了(一个办公区域内最多只有一个核心部门),出于工作效率的考虑,微软希望核心部门之间的移动时间越短越好。对于一个给定的 最大移动时间 k,大楼的 协同值 定义为:有多少个 核心部门对 之间的移动时间不超过 k。由于大楼门禁的限制,不可以走出整个大楼,也不可以登上天台思考人生。你可以认为在办公区域内的移动时间忽略不计,并且在大楼内总是按照最优方案进行移动。
对于一个给定的新大楼设计方案,你能算出方案的协同值么?
输入格式
第一行包含两个正整数 n , k (1 ≤ k ≤ 200020),分别表示大楼的栋数以及最大移动时间。
第二行包含 n 个正整数 h1 , h2 , … , hn (1 ≤ hi ≤ 20),分别表示每栋楼的层数。
接下来一行包含一个正整数 m,表示 核心部门 个数。
接下来 m 行,每行两个正整数 xi,yi(1≤xi≤n,1≤yi≤hxi),表示该核心部门位于第 xi 栋楼的第 yi 层。
输入数据保证 m 个核心部门的位置不会重复。
1≤n,m≤50;
输出格式
输出一个整数,即整个大楼的 协同值。
样例输入
5 7
4 1 1 3 1
3
1 4
3 1
4 3
样例输出
2
样例解释
样例对应题目描述中的图,核心部门 1 和核心部门 3 之间的距离为 8>7,因此不能计入答案。
因为想快些写出来,所以就直接用bfs写了
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stack>
#include<queue>
using namespace std;
int n,k,h[55];
int x[55],y[55];
int m,ans;
int st_x,st_y , ed_x,ed_y;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
int vis[55][55];
int map[55][55];
struct node
{
int x,y;
int step;
};
void bfs()
{
memset(vis,0,sizeof vis);
queue<node>q;
node s;
s.x=st_x;s.y=st_y;
s.step = 0;
q.push(s);
while(!q.empty())
{
s=q.front();
q.pop();
if(s.x==ed_x&&s.y==ed_y)
{
if(s.step<=k)
ans++;
break;
}
for(int i=0;i<4;i++)
{
node p ;
p.x=s.x+dir[i][0];
p.y=s.y+dir[i][1];
p.step= s.step+1;
if(p.x<1||p.y<1||p.x>n||p.y>h[p.x]||vis[p.x][p.y])
continue;
vis[p.x][p.y]=1;
q.push(p);
}
}
while(!q.empty())
q.pop();
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>h[i];
for(int j=1;j<=h[i];j++)
{
map[i][j]=1;
}
}
cin>>m;
for(int i=0;i<m;i++)
cin>>x[i]>>y[i];
ans = 0;
for(int i=0;i<m-1;i++)
{
for(int j=i+1;j<m;j++)
{
st_x = x[i];
st_y = y[i];
ed_x = x[j];
ed_y = y[j];
bfs();
}
}
cout<<ans<<endl;
return 0;
}
③微软大楼的设计方案(中等)
题目描述与2相同,n和m的数据范围变更为1≤n≤200000,1≤m≤2000。
这题我写得似乎有点不对,因为我把过了的放到第二题里WA了,不过还是被我水过去了。
就是找两个点之间最矮的大楼,然后就可以算了,找的话我是用的分区来二分的找,就是把高度相同的作为一区,具体我也讲不太清楚。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
int n,k,x[2020],y[2020],m,ans;
struct node
{
int h;
int x;
}a[200000+1000];
bool cmp(node a,node b)
{
if(a.h==b.h)
return a.x<b.x;
return a.h<b.h;
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
int h;
cin>>h;
a[i].h=h;
a[i].x=i;
}
cin>>m;
for(int i=0;i<m;i++)
cin>>x[i]>>y[i];
ans = 0;
sort(a+1,a+n+1,cmp);
int pos[22][2];
memset(pos,0,sizeof pos);
for(int i=1;i<=n;i++)
{
if(pos[a[i].h][0]==0)
pos[a[i].h][0]=i;
pos[a[i].h][1]=i;
}
for(int i=0;i<m-1;i++)
{
for(int j=i+1;j<m;j++)
{
int mi_h = min(y[i],y[j]);
int mi_x,mx_x;
if(x[i]<x[j])
mi_x=x[i],mx_x=x[j];
else
mi_x=x[j],mx_x=x[i];
int mi=0;
int step = 0;
for(int ll=1;ll<=mi_h;ll++)
{
int l=pos[ll][0],r=pos[ll][1];
int mid=(l+r)/2;
if(a[r].x<mi_x||a[l].x>mx_x)
continue;
while(1)
{
if(a[mid].x>=mi_x&&a[mid].x<=mx_x)
{
mi=ll;
break;
}
if(mid==r||mid==l)
break;
else if(a[mid].x>mi_x)
r=mid;
else
l=mid;
mid = (r+l)/2;
}
if(mi)
break;
}
step = mx_x - mi_x + y[i] + y[j] - 2 * mi;
if(step<=k)
ans++;
}
}
cout<<ans<<endl;
return 0;
}
④微软大楼的设计方案(困难)
题目描述与2相同,n和m的数据范围变更为1≤n,m≤200000。
这题没什么想法。