9005

15084948533
lkh
.key
github_smallzhong
upup
75min智力冲浪
Minuet

yxc

28天前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;

int n;
char s[N];
int ne[N];
bool st[N];

int main()
{
int T;
cin >> T;
while(T --){
scanf("%s", s + 1);
n = strlen(s + 1);
for(int i = 2, j = 0; i <= n; i ++){
while(j && s[i] != s[j + 1]) j = ne[j];
if(s[i] == s[j + 1]) j ++;
ne[i] = j;
}

for(int i = 0; i <= n; i ++) st[i] = false;
for(int i = 1; i < n; i ++) st[ne[i]] = true;

int res = 0;
for(int i = ne[n]; i; i = ne[i])
if(st[i]){
res = i;
break;
}

if(!res) puts("not exist");
else{
s[res + 1] = 0;
printf("%s\n", s + 1);
}

}

return 0;
}


28天前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
int T;
cin >> T;
while(T --){
int n;
cin >> n;
int last = 0;
while(n --){
int l, r;
cin >> l >> r;
if(max(last, l) > r) cout << '0' << ' ';
else{
cout << max(last, l) << ' ';
last = max(last, l) + 1;
}
}
cout << endl;

}
return 0;
}


30天前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 5e5 + 10;

struct Order{
int l, r;
bool operator< (const Order& t) const{
return r < t.r;
}
}order[N];

int main()
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i ++) scanf("%d%d", &order[i].l, &order[i].r);
sort(order, order + n);

int res = 0, ed = 0;
for(int i = 0; i < n; i ++){
if(order[i].l <= ed) continue;
res ++;
ed = order[i].r;
}

cout << res << endl;

return 0;
}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1e5 + 10;

int a[N], b[N];

int na, nb, k, m;

int main()
{
scanf("%d%d%d%d", &na, &nb, &k, &m);

for(int i = 1; i <= na; i ++) scanf("%d", &a[i]);
for(int i = 1; i <= nb; i ++) scanf("%d", &b[i]);

if(a[k] < b[nb - m + 1]) puts("YES");
else puts("NO");

return 0;

}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

int a[N], b[N];
int n;

LL s[N];

bool check(int w[]){
for(int i = 1; i <= n; i ++)
s[i] = s[i - 1] + w[i];

if(s[n] % 2) return false;

unordered_set<LL> S;
S.insert(0);

for(int i = 1; i <= n; i ++){
S.insert(w[i]);
if(S.count(s[i] - s[n] / 2))  return true;
}
return false;
}

int main()
{
int T;
scanf("%d", &T);

while(T --){

scanf("%d", &n);

for(int i = 1, j = n; i <= n; i ++, j --){
scanf("%d", &a[i]);
b[j] = a[i];
}

if(check(a) || check(b)) puts("YES");
else puts("NO");

}

return 0;

}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;

int main()
{
int T;
cin >> T;
while(T --){
LL n;
cin >> n;
LL res = 1;
for(int i = 2; i <= n / i; i ++){
if(n % i == 0) res *= i;

while(n % i == 0) n /= i;
}
res *= n;
cout << res << endl;
}
return 0;

}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 110;

string a[N];

int main()
{

int n, res = 0;
cin >> n;

for(int i = 0; i < n; i ++){
cin >> a[i];
}

for(int i = 0; i < n; i ++){
int cnt = 0;
for(int j = 0; j < n; j ++){
if(a[i] == a[j]) cnt ++;
}
if(cnt > res) res = cnt;
}
cout << res << endl;

return 0;
}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 60;
string a[N];
string s;
int sx, sy, ex, ey;
int n, m;

int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

bool check(vector<int> &q){
int x = sx, y = sy;
for(auto c : s){
x += dx[q[c - '0']];
y += dy[q[c - '0']];
if(x < 0 || x >= n || y < 0 || y >= m || a[x][y] == '#') return false;
if(a[x][y] == 'E') return true;
}
return false;
}

int main()
{
int T;
cin >> T;
while(T --){

cin >> n >> m;

int res = 0;

for(int i = 0; i < n; i ++) cin >> a[i];

cin >> s;

for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++){
if(a[i][j] == 'S') {
sx = i;
sy = j;
}
}

vector<int> q{0, 1, 2, 3};

for(int i = 0; i < 24; i ++){

if(check(q)) res ++;
next_permutation(q.begin(), q.end());
}

cout << res << endl;
}
return 0;
}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 2e5 + 10;

int a[N * 2];

int main()
{
int T;
cin >> T;
while(T --){
int n;
cin >> n;
for(int i = 0; i < n; i ++)
{
scanf("%d", &a[i]);
a[i + n] = a[i];
}
int res = 0;
for(int i = 0; i < 2 * n - 1; i ++){
while(!a[i] && i < 2 * n) i ++;
if(i == 2 * n) break;
int j = i;
while(a[j]) j ++;
res = max(res, j - i);
i = j - 1;
}
cout << res << endl;

}

return 0;
}


1个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1010, INF = 1e9;

int a[N];

int main()
{
int T;
cin >> T;
while(T --){
int n, k = 0;
cin >> n;
int res = INF;
for(int i = 0; i < n; i ++) cin >> a[i];

for(int i = 1; i <= 100; i ++){
int sum = 0;
for(int j = 0; j < n; j ++){
if(abs(a[j] - i) <= 1)  continue;
sum += abs(a[j] - i) - 1;
}
if(sum < res) {
res = sum;
k = i;
}
}
printf("%d %d\n", k, res);

}

return 0;
}