mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-10-29 11:33:03 +00:00
Compare commits
2 Commits
2e2a747e5e
...
5546dd0eed
| Author | SHA1 | Date | |
|---|---|---|---|
| 5546dd0eed | |||
| 1f0526403f |
@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
add_compile_options(-Wall)
|
||||
add_compile_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer)
|
||||
add_link_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer)
|
||||
# add_compile_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer)
|
||||
# add_link_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
|
||||
@ -1,24 +1,39 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
using ll = int64_t;
|
||||
|
||||
const ll maxn = 1000+5;
|
||||
#define sl static inline
|
||||
|
||||
const ll maxn = 1005;
|
||||
ll n, m;
|
||||
ll a[maxn][maxn];
|
||||
struct D{
|
||||
ll x,y,d;
|
||||
bool is2,ish;
|
||||
};
|
||||
std::deque<D> d;
|
||||
bool vis[maxn][maxn][4];
|
||||
const ll dir[4][2]={
|
||||
{1,0},
|
||||
{-1,0},
|
||||
{0,1},
|
||||
{0,-1}
|
||||
int a[maxn][maxn];
|
||||
bool vis[maxn][maxn][4][2];
|
||||
int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
|
||||
struct Q {
|
||||
Q(ll s, ll x, ll y, ll dir, bool is2) : s(s), x(x), y(y), dir(dir), is2(is2) {
|
||||
}
|
||||
ll s, x, y, dir;
|
||||
bool is2;
|
||||
};
|
||||
std::deque<Q> q;
|
||||
|
||||
sl bool check(ll x, ll y, ll dir, bool is2) {
|
||||
if (x < 1 || x > n || y < 1 || y > m)
|
||||
return false;
|
||||
if (a[x][y] == 0)
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::iostream::sync_with_stdio(false);
|
||||
@ -30,54 +45,65 @@ int main(){
|
||||
std::cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
d.emplace_back(1,1,0,false);
|
||||
while (d.size()) {
|
||||
auto[x,y,dd,is2,ish] = d.front();
|
||||
d.pop_front();
|
||||
if(ish && a[x][y]==4){
|
||||
ll nx = x+dir[dd][0], ny=y+dir[dd][1];
|
||||
if(a[nx][ny]==3){
|
||||
if(vis[nx][ny][is2])continue;
|
||||
}else if(a[nx][ny]==4){
|
||||
if(vis[nx][ny][dd])continue;
|
||||
}else if(vis[nx][ny][0])continue;
|
||||
|
||||
if(ll na=a[nx][ny];na==0){
|
||||
continue;
|
||||
}else if(na==1){
|
||||
d.emplace_back(nx,ny,dd,false,false);
|
||||
vis[nx][ny][0]=true;
|
||||
}else if(na==2){
|
||||
d.emplace_back(nx,ny,dd,true,false);
|
||||
vis[nx][ny][0]=true;
|
||||
}else if(na==3){
|
||||
continue;
|
||||
}else if(na==4){
|
||||
d.emplace_back(nx,ny,dd,false,true);
|
||||
vis[nx][ny][dd]=true;
|
||||
q.emplace_back(0, 1, 1, 0, false);
|
||||
vis[1][1][0][false] = true;
|
||||
|
||||
while (q.size()) {
|
||||
auto [s, x, y, dd, is2] = q.front();
|
||||
q.pop_front();
|
||||
|
||||
if (x == n && y == m) {
|
||||
std::cout << s << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a[x][y] == 4) {
|
||||
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))
|
||||
continue;
|
||||
|
||||
if (a[nx][ny] == 4) {
|
||||
|
||||
vis[nx][ny][dd][false] = true;
|
||||
} else {
|
||||
|
||||
vis[nx][ny][0][nis2] = true;
|
||||
}
|
||||
|
||||
q.emplace_back(s + 1, nx, ny, dd, nis2);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ll i = 0; i < 4; i++) {
|
||||
ll nx = x + dir[i][0], ny = y + dir[i][1];
|
||||
|
||||
if(ll na = a[nx][ny];na==0){
|
||||
if (nx < 1 || nx > n || ny < 1 || ny > m)
|
||||
continue;
|
||||
}else if(na==1){
|
||||
d.emplace_back(nx,ny,i,false,false);
|
||||
vis[nx][ny][0]=true;
|
||||
}else if(na==2){
|
||||
d.emplace_back(nx,ny,i,true,false);
|
||||
vis[nx][ny][0]=true;
|
||||
}else if(na==3){
|
||||
if(is2){
|
||||
d.emplace_back(nx,ny,i,true,false);
|
||||
vis[nx][ny][is2]=true;
|
||||
}
|
||||
}else if(na==4){
|
||||
d.emplace_back(nx,ny,i,false,true);
|
||||
vis[nx][ny][i]=true;
|
||||
|
||||
bool nis2 = is2;
|
||||
if (a[nx][ny] == 2)
|
||||
nis2 = true;
|
||||
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 {
|
||||
vis[nx][ny][0][nis2] = true;
|
||||
}
|
||||
|
||||
q.emplace_back(s + 1, nx, ny, i, nis2);
|
||||
}
|
||||
}
|
||||
std::cout << "-1\n";
|
||||
}
|
||||
@ -6,15 +6,15 @@ using ll = int64_t;
|
||||
|
||||
|
||||
int main(){
|
||||
ll n,k,m;
|
||||
std::cin>>n>>k>>m;
|
||||
ll n=100,k=100,m=1;
|
||||
// std::cin>>n>>k>>m;
|
||||
for(ll x=25;x<=25;x++){
|
||||
ll g=0;
|
||||
for(ll i=1;i<=k;i++){
|
||||
ll y=(n-g)/x;
|
||||
y=std::max(y,m);
|
||||
printf("(n-g)=%lld, y=%lld, x=%lld\n",n-g,y,x);
|
||||
g+=y;
|
||||
printf("i=%lld, g=%lld\n",i,g);
|
||||
}
|
||||
printf("-- x=%lld, g=%lld\n\n",x,g);
|
||||
}
|
||||
|
||||
44
src/10/16/P6003.cpp
Normal file
44
src/10/16/P6003.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
using ll = int64_t;
|
||||
#define sl static inline
|
||||
ll n,k,m;
|
||||
|
||||
sl bool check(ll x){
|
||||
ll g=0;
|
||||
for(ll i=1;i<=k;i++){
|
||||
ll y=(n-g)/x;
|
||||
if(y<m){
|
||||
g+=m*(k-i+1);
|
||||
return g>=n;
|
||||
}else{
|
||||
ll nxt = ((n-g)-(y*x))/y+1;
|
||||
nxt=std::min(nxt,k-i+1);
|
||||
g+=y*nxt;
|
||||
i+=nxt-1;
|
||||
}
|
||||
}
|
||||
return g>=n;
|
||||
}
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin>>n>>k>>m;
|
||||
ll l=1,r=n,ans=0,mid;
|
||||
while(l<r){
|
||||
mid=(l+r)/2;
|
||||
// printf("l=%lld, mid=%lld, r=%lld\n",l,mid,r);
|
||||
if(check(mid)){
|
||||
ans=mid;
|
||||
l=mid+1;
|
||||
}else{
|
||||
r=mid;
|
||||
}
|
||||
}
|
||||
std::cout<<ans<<"\n";
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user