生活随笔
收集整理的這篇文章主要介紹了
Acwing第 23 场周赛【完结】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
- 4003. 完全平方數(shù)【簽到】
- 4004. 傳送陣【floodfill 暴力】
- 4005. 取石子游戲【博弈論】
4003. 完全平方數(shù)【簽到】
https://www.acwing.com/problem/content/4006/
#include<bits/stdc++.h>
using namespace std
;
int n
;
int main(void)
{cin
>>n
;int ans
=-1e9;while(n
--){int x
; cin
>>x
;int temp
=sqrt(x
);if(temp
*temp
!=x
) ans
=max(ans
,x
);}cout
<<ans
<<endl
;return 0;
}
4004. 傳送陣【floodfill 暴力】
https://www.acwing.com/problem/content/4007/
暴力求連通塊的所有的點,然后暴力枚舉取一個min
#include<bits/stdc++.h>
using namespace std
;
typedef pair
<int,int> PII
;
const int N
=1e2+10;
int n
,x
,y
,xx
,yy
;
string s
[N
];
int dx
[4]={-1,0,0,1};
int dy
[4]={0,-1,1,0};
int st
[N
][N
]={0};
vector
<PII
>A
,B
;
vector
<PII
> bfs(int x
,int y
)
{vector
<PII
>C
;queue
<PII
>q
; q
.push({x
,y
}); st
[x
][y
]=1;while(q
.size()){auto t
=q
.front(); q
.pop();int x
=t
.first
,y
=t
.second
;C
.push_back({x
,y
});for(int i
=0;i
<4;i
++){int tempx
=x
+dx
[i
];int tempy
=y
+dy
[i
];if(tempx
<0||tempx
>=n
||tempy
<0||tempy
>=n
) continue;if(s
[tempx
][tempy
]=='1') continue;if(st
[tempx
][tempy
]) continue;q
.push({tempx
,tempy
});st
[tempx
][tempy
]=1;}}return C
;
}
int main(void)
{cin
>>n
>>x
>>y
>>xx
>>yy
;for(int i
=0;i
<n
;i
++) cin
>>s
[i
];A
=bfs(x
-1,y
-1);B
=bfs(xx
-1,yy
-1);int ans
=1e9;for(int i
=0;i
<A
.size();i
++)for(int j
=0;j
<B
.size();j
++){int a
=A
[i
].first
,b
=A
[i
].second
;int c
=B
[j
].first
,d
=B
[j
].second
;ans
=min(ans
,(a
-c
)*(a
-c
)+(b
-d
)*(b
-d
));}cout
<<ans
;return 0;
}
4005. 取石子游戲【博弈論】
https://www.acwing.com/problem/content/4008/
#include<bits/stdc++.h>
using namespace std
;
int main(void)
{int t
; cin
>>t
;while(t
--){int n
,k
; cin
>>n
>>k
;if(k
%3){if(n
%3) puts("Alice");else puts("Bob");}else{n
=n
%(k
+1);if(n
==k
|| n
%3 ) puts("Alice");else puts("Bob");}}return 0;
}
總結(jié)
以上是生活随笔為你收集整理的Acwing第 23 场周赛【完结】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。