signed

PYYZ

782

noSorryMaker
BT7274
C++_2

Xu_
Arctic_1024
RyanMoriarty
FORGE
khalil
XUGUOHAO

Rain丶bow
Improve

signed
10小时前

signed
10小时前
待补坑


signed
1天前
#include <iostream>
#include <vector>
using namespace std;
using T = pair<int, int>;

const int N = 60;

const int dr[] = { -1, 0, 1, 0 }, dc[] = { 0, 1, 0, -1 };

int n, m;
char g[N][N];
bool st[N][N];
vector<T> block[2];

void dfs (vector<T> & block, int x, int y)
{
st[x][y] = true;
block.push_back({x, y});
for (int i = 0; i < 4; i ++ )
{
int dx = x + dr[i], dy = y + dc[i];
if (st[dx][dy] || dx < 1 || dx > n || dy < 1 || dy > m || g[dx][dy] != 'X') continue;
dfs(block, dx, dy);
}
}

int main ()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> (g[i] + 1);

for (int i = 1, which = 0; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
if (!st[i][j] && g[i][j] == 'X') dfs(block[which ++], i, j);

int dist = 1e9 + 10;
for (auto a : block[0])
for (auto b : block[1])
dist = min(abs(a.first - b.first) + abs(a.second - b.second), dist);

cout << dist - 1 << endl;
return 0;
}



signed
1天前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k;
int b[1000005];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=k;i++){
int l,r;
scanf("%d%d",&l,&r);
b[l]++;
b[r+1]--;
}
for(int i=1;i<=n;i++) b[i]+=b[i-1];
sort(b+1,b+n+1);
printf("%d\n",b[n/2+1]);
return 0;
}


signed
1天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
string n,m;
int a,b;
int s1[105],s2[205],t,k;
int main(){
cin >> n >> m;
int l1 = n.size() - 1 , l2 = m.size() - 1;
for (int i = 0; i <= l1; i ++ )
a=a*2+n[i]-'0';
for (int i = 0; i <= l2; i ++ )
b=b*3+m[i]-'0';

for (int i = 0; i <= l1; i ++ ){
if(n[i]=='0') s1[++k]=a+pow(2,l1-i);
else s1[++k]=a-pow(2,l1-i);
}
t=k,k=0;
for (int i = 0; i <= l2; i ++ ){
if(m[i]=='0') s2[++k]=b+pow(3,l2-i),s2[++k]=b+2*pow(3,l2-i);
else if(m[i]=='1') s2[++k]=b-pow(3,l2-i),s2[++k]=b+pow(3,l2-i);
else s2[++k]=b-pow(3,l2-i),s2[++k]=b-2*pow(3,l2-i);
}
for(int i=1;i<=t;i++)
for(int j=1;j<=k;j++)
if(s1[i]==s2[j]){
cout << s1[i];
return 0;
}
return 0;
}


signed
2天前

signed
2天前

signed
2天前

signed
1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5+5 , M=1e9+7;
int a,b,n;
LL jc[N],ny[N];
LL qmi(LL a, LL k)  // 求a^k mod p
{
LL res=1;
while (k)
{
if (k & 1) res = res * a % M;
a = a * a % M;
k >>= 1;
}
return res;
}
int main()
{
jc[0]=ny[0]=1;
for (int i = 1; i <= N; i ++ )
jc[i]=jc[i-1]*i%M;
for (int i = 1; i <= N; i ++ )
ny[i]=ny[i-1]*qmi(i,M-2)%M;
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ){
scanf("%d%d", &a, &b);
printf("%lld\n",jc[a]*ny[a-b]%M*ny[b]%M);
}
return 0;
}


signed
1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 105;
int n;
int a[N][N];
int gauss()
{
int c, r;
for (c = 0, r = 0; c < n; c ++ )
{
int t = r;
for (int i = r; i < n; i ++ )
if (a[i][c]){
t = i;
break;
}

if (!a[t][c]) continue;

for (int i = c; i <= n; i ++ ) swap(a[t][i], a[r][i]);
for (int i = r + 1; i < n; i ++ )
if (a[i][c])
for (int j = c; j <= n; j ++ )
a[i][j] ^= a[r][j];

r ++ ;
}

if (r < n)
{
for (int i = r; i < n; i ++ )
if (a[i][n])
return 2; // 无解
return 1; // 有无穷多组解
}

for (int i = n - 1; i >= 0; i -- )
for (int j = i + 1; j < n; j ++ )
a[i][n] ^= a[i][j] & a[j][n];

return 0; // 有唯一解
}

int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ )
for (int j = 0; j <= n; j ++ )
scanf("%d", &a[i][j]);
int t=gauss();
if(t==0){
for (int i = 0; i < n; i ++ )
printf("%d\n",a[i][n]);
}
if(t==1) puts("Multiple sets of solutions");
if(t==2) puts("No solution");
return 0;
}