mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-10-17 21:42:25 +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;
|
||||
if (a[x][y] == 3 && !is2)
|
||||
return false;
|
||||
|
||||
if (a[x][y] == 4) {
|
||||
return !vis[x][y][dir][false];
|
||||
} else {
|
||||
return !vis[x][y][0][is2];
|
||||
}
|
||||
return !vis[x][y][dir][is2];
|
||||
}
|
||||
|
||||
int main() {
|
||||
@ -57,25 +52,14 @@ int main() {
|
||||
std::cout << s << "\n";
|
||||
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];
|
||||
|
||||
if (nx < 1 || nx > n || ny < 1 || ny > m)
|
||||
continue;
|
||||
|
||||
bool nis2 = (a[nx][ny] == 2);
|
||||
|
||||
if (!check(nx, ny, dd, nis2))
|
||||
if (!check(nx, ny, dd, is2))
|
||||
continue;
|
||||
|
||||
if (a[nx][ny] == 4) {
|
||||
|
||||
vis[nx][ny][dd][false] = true;
|
||||
} else {
|
||||
|
||||
vis[nx][ny][0][nis2] = true;
|
||||
}
|
||||
vis[nx][ny][dd][nis2] = true;
|
||||
|
||||
q.emplace_back(s + 1, nx, ny, dd, nis2);
|
||||
continue;
|
||||
@ -93,16 +77,17 @@ int main() {
|
||||
if (a[nx][ny] == 4)
|
||||
nis2 = false;
|
||||
|
||||
if (!check(nx, ny, i, nis2))
|
||||
continue;
|
||||
|
||||
if (a[nx][ny] == 4) {
|
||||
vis[nx][ny][i][false] = true;
|
||||
} else {
|
||||
if(a[nx][ny]==4){
|
||||
if (!check(nx, ny, i, is2))
|
||||
continue;
|
||||
vis[nx][ny][i][nis2] = true;
|
||||
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);
|
||||
}
|
||||
|
||||
q.emplace_back(s + 1, nx, ny, i, nis2);
|
||||
}
|
||||
}
|
||||
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