今晚 CF E
2026-08-10 01:09:41
发布于:浙江
样例写错了,更新我没看到……
先放代码,证明我打了。
#include <bits/stdc++.h>
#include <assert.h>
std::string c;
int T;
namespace cjdst{
typedef long long ll;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
void init(){
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
}
void exgcd(ll a, ll b, ll d, ll &x, ll &y){
if(!b){
x = d / a, y = 0;
return;
}
exgcd(b, a % b, d, y, x);
y -= a / b * x;
}
void solve(){
int n, m = 0;
std::cin >> n;
std::vector <std::string> a(n + 5);
ll cur1 = 0, cur2 = 0;
for(int i = 1; i <= n; i++){
std::cin >> a[i];
a[i] = " " + a[i] + " ";
for(int j = 1; j <= n; j++){
if(a[i][j] == '#') cur1 += i, cur2 += j, m++;
}
}
if(c == "second"){
ll x, k1, y, k2;
exgcd(m, n, cur1, x, k1);
exgcd(m, n, cur2, y, k2);
// std::cout << x << ' ' << y << '\n';
x = (x % n + n) % n;
y = (y % n + n) % n;
if(!x) x += n;
if(!y) y += n;
std::cout << x << ' ' << y << '\n';
return;
}
ll x, y;
std::cin >> x >> y;
ll x1 = m * x - cur1, y1 = m * y - cur2;
x1 = (x1 % n + n) % n;
y1 = (y1 % n + n) % n;
if(!x1 && !y1){
std::cout << "1 1 1 1\n";
return;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] == '#' && a[(i + x1 - 1) % n + 1][(j + y1 - 1) % n + 1] == '.'){
std::cout << i << ' ' << j << ' ' << (i + x1 - 1) % n + 1 << ' ' << (j + y1 - 1) % n + 1 << '\n';
return;
}
}
}
}
}
int main(){
cjdst::init();
std::cin >> c >> T;
for(int _ = 1; _ <= T; _++){
cjdst::solve();
}
}
全部评论 3
d
1周前 来自 浙江
1d
1周前 来自 浙江
1大佬把E做出来了???!!吓哭了




,大佬教我c++/bx/bx1周前 来自 广东
0

























有帮助,赞一个