mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-16 20:23:00 +00:00
feat: 添加P10136解题代码并优化P4818逻辑
添加新的解题代码P10136.cpp,实现特定算法功能。同时优化P4818.cpp中的路径检查逻辑,简化条件判断并修复潜在错误。
This commit is contained in:
parent
0937a7a512
commit
8ab26b6389
@ -27,12 +27,7 @@ sl bool check(ll x, ll y, ll dir, bool is2) {
|
|||||||
return false;
|
return false;
|
||||||
if (a[x][y] == 3 && !is2)
|
if (a[x][y] == 3 && !is2)
|
||||||
return false;
|
return false;
|
||||||
|
return !vis[x][y][dir][is2];
|
||||||
if (a[x][y] == 4) {
|
|
||||||
return !vis[x][y][dir][false];
|
|
||||||
} else {
|
|
||||||
return !vis[x][y][0][is2];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -58,24 +53,13 @@ int main() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a[x][y] == 4) {
|
if (a[x][y] == 4 && check(x+dir[dd][0], y+dir[dd][1], dd, is2)) {
|
||||||
ll nx = x + dir[dd][0], ny = y + dir[dd][1];
|
ll nx = x + dir[dd][0], ny = y + dir[dd][1];
|
||||||
|
|
||||||
if (nx < 1 || nx > n || ny < 1 || ny > m)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool nis2 = (a[nx][ny] == 2);
|
bool nis2 = (a[nx][ny] == 2);
|
||||||
|
if (!check(nx, ny, dd, is2))
|
||||||
if (!check(nx, ny, dd, nis2))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (a[nx][ny] == 4) {
|
vis[nx][ny][dd][nis2] = true;
|
||||||
|
|
||||||
vis[nx][ny][dd][false] = true;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
vis[nx][ny][0][nis2] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
q.emplace_back(s + 1, nx, ny, dd, nis2);
|
q.emplace_back(s + 1, nx, ny, dd, nis2);
|
||||||
continue;
|
continue;
|
||||||
@ -93,16 +77,17 @@ int main() {
|
|||||||
if (a[nx][ny] == 4)
|
if (a[nx][ny] == 4)
|
||||||
nis2 = false;
|
nis2 = false;
|
||||||
|
|
||||||
if (!check(nx, ny, i, nis2))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(a[nx][ny]==4){
|
if(a[nx][ny]==4){
|
||||||
vis[nx][ny][i][false] = true;
|
if (!check(nx, ny, i, is2))
|
||||||
} else {
|
continue;
|
||||||
vis[nx][ny][0][nis2] = true;
|
vis[nx][ny][i][nis2] = true;
|
||||||
}
|
|
||||||
|
|
||||||
q.emplace_back(s + 1, nx, ny, i, nis2);
|
q.emplace_back(s + 1, nx, ny, i, nis2);
|
||||||
|
}else{
|
||||||
|
if(!check(nx, ny, 0, is2))
|
||||||
|
continue;
|
||||||
|
vis[nx][ny][0][nis2] = true;
|
||||||
|
q.emplace_back(s + 1, nx, ny, 0, nis2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "-1\n";
|
std::cout << "-1\n";
|
||||||
|
|||||||
58
src/10/16/P10136.cpp
Normal file
58
src/10/16/P10136.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <set>
|
||||||
|
using ll = int64_t;
|
||||||
|
|
||||||
|
const ll maxn = 1e4+5;
|
||||||
|
ll n,a[maxn],mina=4e9+7,ans;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
std::iostream::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::cin>>n;
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
std::cin>>a[i];
|
||||||
|
mina=std::min(mina,a[i]);
|
||||||
|
}
|
||||||
|
std::sort(a+1,a+1+n);
|
||||||
|
n=std::unique(a+1,a+1+n)-(a+1);
|
||||||
|
if(n<4){
|
||||||
|
std::cout<< (mina/4)*(mina/4+1)/2 <<"\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
std::set<ll> yz;
|
||||||
|
for(ll i=1;i<=4;i++){
|
||||||
|
for(ll j=i+1;j<=4;j++){
|
||||||
|
if(i==j)continue;
|
||||||
|
ll now = std::abs(a[i]-a[j]);
|
||||||
|
for(ll k=1;k*k<=now;k++){
|
||||||
|
if(now%k==0){
|
||||||
|
yz.insert(k);
|
||||||
|
yz.insert(now / k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::set<ll> sl;
|
||||||
|
for(const ll l:yz){
|
||||||
|
if (l == 0) continue;
|
||||||
|
if(l*4>mina)continue;
|
||||||
|
std::set<ll> cs;
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
cs.insert(a[i]%l);
|
||||||
|
if(cs.size()>3){
|
||||||
|
goto nxt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sl.insert(l);
|
||||||
|
nxt:;
|
||||||
|
}
|
||||||
|
for(ll i:sl){
|
||||||
|
ans+=i;
|
||||||
|
}
|
||||||
|
std::cout<<ans<<"\n";
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user