AKG

5782

visga
chercom

Ethanyyc

holly_6
zhuziyue321
sealt
kzyz
.Zero

miracle_61

wangsyCHN
yxc的小迷妹

L-L
UyAey

AKG
9小时前
#include<bits/stdc++.h>
#include <clocale>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--)solve();
return 0;
}

const int nn = 111;
struct lc
{
int x, y, z;
};
char g[nn][nn][nn];
int l, r, c;
lc s;
queue<pair<lc, int>> q;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }, dz[3] = { -1,0,1 };
void solve()
{
while (cin >> l >> r >> c)
{
if (!l && !r && !c)return;
for (int i = 1; i <= l; i++)
for (int j = 1; j <= r; j++)
for (int k = 1; k <= c; k++)
cin >> g[i][j][k];

for (int i = 1; i <= l; i++)
for (int j = 1; j <= r; j++)
for (int k = 1; k <= c; k++)
if (g[i][j][k] == 'S')
s.x = j, s.y = k, s.z = i, g[i][j][k] = '#';

queue<pair<lc, int>>().swap(q);
q.push({ s,0 });
while (!q.empty())
{
lc k = q.front().first;
int cnt = q.front().second;
q.pop();
int x = k.x, y = k.y, z = k.z;
for (int j = 0; j < 4; j++)
{
int xx = x + dx[j], yy = y + dy[j], zz = z + dz[1];
if (xx<1 || xx>r || yy<1 || yy>c || zz<1 || zz>l || g[zz][xx][yy] == '#')continue;
else
{
if (g[zz][xx][yy] == 'E')
{
cout << "Escaped in " << cnt + 1 << " minute(s)." << endl;
goto loop;
}
else
{
q.push({ {xx,yy,zz},cnt + 1 });
g[zz][xx][yy] = '#';
}
}
}
for (int i = 0; i < 3; i++)
{
if (i == 1)continue;
int zz = z + dz[i];
if (zz<1 || zz>l || g[zz][x][y] == '#')continue;
else
{
if (g[zz][x][y] == 'E')
{
cout << "Escaped in " << cnt + 1 << " minute(s)." << endl;
goto loop;
}
else
{
q.push({ {x,y,zz},cnt + 1 });
g[zz][x][y] = '#';
}
}
}
}
cout << "Trapped!" << endl;
loop:;
}
}


AKG
10小时前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while(tt--)solve();
return 0;
}

void solve()
{
int n;
int m = -1e18,deep = 0;
cin>>n;
vector<int> a(n+111);
for(int i = 1;i<=n;i++)cin>>a[i];
int len = 1;
for(int i = 1, j = 1;i<=n;)
{
int res = 0;
while(j<=n&&j-i<len)res+=a[j],j++;
//m = max(m,res);
if(res>m)m = res, deep = len;
i = j;
len*=2;
}
int cnt = 0;
while(deep)deep/=2,cnt++;
cout<<cnt;
}


AKG
22小时前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin>>tt;
while(tt--)solve();
return 0;
}

char g[1111][1111];
#define pii pair<int,int>
#define ft first
#define sd second
queue<pii> q;
int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};

void solve()
{
int n;
cin>>n;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
cin>>g[i][j];

int res = 0;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
{
if(g[i][j]=='#')
{
q.push({i,j});
g[i][j] = '*';
int cnt = 0;
int ti = 0;
int c = 0;
while(q.size())
{
int x = q.front().ft, y = q.front().sd;
q.pop();
ti++;
cnt = 0;
// if(g[i][j]=='#')
// cnt++,g[i][j] = '*';
//else continue;
for(int i = 0;i<4;i++)
{
int xx = x + dx[i], yy = y + dy[i];
if(xx<1||xx>n||yy<1||yy>n)continue;
if(g[xx][yy] == '.')cnt=true;
if(g[xx][yy] == '#')
{
q.push({xx,yy});
g[xx][yy] = '*';
}
}
//cout<<c<<' '<<cnt<<endl;
c+=cnt;
//if(!cnt)g[x]
}
//cout<<c<<' '<<ti<<endl;
if(c==ti)res++;
}

}
cout<<res;
}


AKG
23小时前
#include<iostream>
#include <locale>
using namespace std;
const int nn = 111111;
int e[nn],ne[nn],idx = 0;
{
e[++idx] = x;
ne[idx] = ne[0];
ne[0] = idx;
}
void dlt(int k)
{
ne[k] = ne[ne[k]];
}
void insert(int k,int x)
{
e[++idx] = x;
ne[idx] = ne[k];
ne[k] = idx;
}
int main()
{
int m;
cin>>m;
while(m--)
{
char op; int k, x;
cin>>op;
if(op=='H')
{
cin>>x;
}
else if(op=='D')
{
cin>>k;
dlt(k);
}
else
{
cin>>k>>x;
insert(k,x);
}
}
for(int i = ne[0];i;i=ne[i])
cout<<e[i]<<' ';
}


AKG
1天前

#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int a[N], b[N];
int main()
{
int n, cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], b[a[i]] = i;

for (int i = 1; i <= n; i++)
if (a[i] != i)
swap(a[b[i]], a[i]),
swap(b[a[b[i]]], b[i]),
cnt++;

cout << cnt;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int a[N], b[N];
int main()
{
int n, cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];

for (int i = 1; i <= n; i++)
while(a[i]!=i)swap(a[i], a[a[i]]), cnt++;

cout << cnt;
}


AKG
1天前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin>>tt;
while (tt--)solve();
return 0;
}

#define pii pair<int,int>
#define ft first
#define sd second

const int nn = 111;
int n, m;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };

void solve()
{
int n, m;
while (cin >> m >> n)
{
if (!n || !m)return;
int cnt = 0;
pii s;
char g[nn][nn] = {};
bool t[nn][nn] = {};
for (int i = 1; i <= n; i++)cin >> &g[i][1];

// for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)cout << g[i][j] << " \n"[j == m];

for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
if(g[i][j]=='@')s = {i,j};

t[s.ft][s.sd] = true;
queue<pii> q;
q.push(s);

while(!q.empty())
{
auto k = q.front();
q.pop();
int x = k.ft , y = k.sd;
for(int i = 0;i<4;i++)
{
int xx = x+dx[i],yy = y+dy[i];
if (xx<1 || xx>n || yy<1 || yy>m || g[xx][yy] == '#' || t[xx][yy])continue;
t[xx][yy] = true;
cnt++;
q.push({xx,yy});
}
}
cout<<cnt+1<<endl;
}
}


AKG
1天前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
cin >> tt;
while (tt--)solve();
return 0;
}

#define pii pair<int,int>
#define ft first
#define sd second

void solve()
{
int r, c;
pii s, e;
cin >> r >> c;
vector<vector<char> > g(r + 1, vector<char>(c + 1));
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cin >> g[i][j];

for(int i = 1;i<=r;i++)
for (int j = 1; j <= c; j++)
{
if (g[i][j] == 'S')s = { i,j };
if (g[i][j] == 'E')e = { i,j };
}

queue<pii> q;
vector<vector<int> >dis(r + 1, vector<int>(c + 1, -1));
dis[s.ft][s.sd] = 0;
q.push(s);
int dx[4] = { -1,0,+1,0 }, dy[4] = { 0,+1,0,-1 };
while (q.size())
{
pii k = q.front();
q.pop();
int x = k.ft, y = k.sd;
for (int i = 0; i < 4; i++)
{
int xx = x + dx[i], yy = y + dy[i];
if (xx<1 || xx>r || yy<1 || yy>c || dis[xx][yy] != -1 || g[xx][yy] == '#')continue;
dis[xx][yy] = dis[x][y] + 1;
q.push({ xx,yy });
}
}
if (dis[e.ft][e.sd] == -1)cout << "oop!" << endl;
else cout << dis[e.ft][e.sd] << endl;
}


AKG
1天前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--)solve();
return 0;
}

#define pii pair<int,int>
#define ft first
#define sd second
vector<pii> v;
int cnt[111111];
bool t[111111];
const int T = 1e5 + 11;
void solve()
{
int n, d, k;
cin >> n >> d >> k;
for (int i = 1; i <= n; i++)
{
int a, b;
cin >> a >> b;
v.emplace_back(a, b);
}
sort(v.begin(), v.end());
for (int i = 0, j = 0; i < v.size() && j < v.size(); i++)
{
cnt[v[i].sd]++;
while (v[i].ft - v[j].ft >= d)
{
cnt[v[j].sd]--;
j++;
}
if (cnt[v[i].sd] >= k)t[v[i].sd] = true;
}
for (int i = 0; i <= T; i++)
if (t[i])cout << i << endl;
}


AKG
2天前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--)solve();
return 0;
}

#define pii pair<int,int>
#define ft first
#define sd second
const int nn = 1e5 + 11;
pii a[nn];
int last[nn], sc[nn];
bool st[nn];
int n, m, ti;
void solve()
{
cin >> n >> m >> ti;
for (int i = 0; i < m; i++)cin >> a[i].ft >> a[i].sd;
sort(a, a + m);

//for(int i = 0;i<m;i++)cout<<a[i].ft<<' '<<a[i].sd<<endl;

for (int i = 0; i < m; )
{
int j = i;
while (j < m && a[i] == a[j])j++;
int t = a[i].ft, id = a[i].sd;

//  cout<<sc[id]<<"  "<<id<<"  "<<t<<endl;

sc[id] -= t - last[id] - 1;
if (sc[id] < 0)sc[id] = 0;
if (sc[id] <= 3)st[id] = false;
last[id] = t;
sc[id] += (j - i) * 2;
if (sc[id] > 5) st[id] = true;

i = j;
}

//for (int i = 0; i < n; i++)cout << sc[i] << " \n"[i == n - 1];

for (int i = 0; i <= n; i++)
{
if (last[i] < ti)sc[i] -= ti - last[i];
if (sc[i] <= 3)st[i] = false;
}
int res = 0;
for (int i = 0; i <= n; i++)res += st[i];
cout << res;
}


AKG
2天前
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--)solve();
return 0;
}

#define lowbit(x) x&-x
#define pii pair<int,int>
#define ft first
#define sd second
int n;
vector<int>tr;
vector<int>sum;
{
for (int i = x; i <= n; i += lowbit(i))tr[i]++;
}
{
int res = 0;
for (int i = x; i; i -= lowbit(i))res += tr[i];
return res;
}
int cmp(pii a, pii b)
{
if (a.ft != b.ft)return a.ft > b.ft;
else return a.sd > b.sd;
}
void solve()
{
cin >> n;
vector<pii> h(n + 1);
tr.resize(n + 1);
sum.resize(n + 1);
for (int i = 1; i <= n; i++)
cin >> h[i].ft, h[i].sd = i;

sort(h.begin() + 1, h.end(), cmp);

for (int i = 1; i <= n; i++)
{
int k = h[i].sd;
}
tr.assign(n + 1, 0);
for (int i = n; i > 0; i--)
{
int k = h[i].sd;