\ (CF \ 634 \ (Div3) \)
\(UN.\)
Dado \ (n \) , pregunte cuántos enteros positivos \ (a, \ b \) tales que \ (a + b = n \) y \ (a> b \)
Si \ (n \) es par, entonces \ (ans = n / 2-1 \)
Si \ (n \) es impar, entonces \ (ans = n / 2 \)
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define arrayDebug(a, l, r) for(int i = l; i <= r; ++i) printf("%d%c", a[i], " \n"[i == r])
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int DX[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 0, 1, 0, -1, -1, 1, 1, -1};
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;
const double PI = acos(-1);
const double EPS = 1e-6;
using namespace std;
inline int read()
{
char c = getchar();
int ans = 0, f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {ans = ans * 10 + c - '0'; c = getchar();}
return ans * f;
}
int t, n;;
int main()
{
t = read();
while(t--) {
n = read();
int ans = 0;
if(n % 2) ans = n / 2;
else ans = n / 2 - 1;
printf("%d\n", ans);
}
return 0;
}
\(SI.\)
Construya una cadena de longitud \ (n \) para que cada subcadena de longitud \ (a \) contenga solo \ (b \) caracteres diferentes
Construido de la siguiente manera
De acuerdo con la orden antes de que el primer llenado \ (b \) letras minúsculas, y el resto de \ - (a b \) posición para llenar las primeras \ (B \) caracteres
Rellene dicha subcadena \ (s \) con toda la cadena de longitud \ (n \)
Por ejemplo, ejemplo \ (7 \ 5 \ 3 \)
Construya \ (s = abccc \) y la respuesta es \ (abcccab \)
La comprensión perceptiva es que una serpiente codiciosa se mueve en la subcadena \ (s \) . La construcción correcta de \ (s \) garantiza la corrección de toda la cadena ...
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define arrayDebug(a, l, r) for(int i = l; i <= r; ++i) printf("%d%c", a[i], " \n"[i == r])
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int DX[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 0, 1, 0, -1, -1, 1, 1, -1};
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;
const double PI = acos(-1);
const double EPS = 1e-6;
using namespace std;
inline int read()
{
char c = getchar();
int ans = 0, f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {ans = ans * 10 + c - '0'; c = getchar();}
return ans * f;
}
int t, a, b, c;
int main()
{
t = read();
while(t--) {
a = read(), b = read(), c = read();
string s = "";
for(int i = 0; i < c; ++i)
s += 'a' + i;
for(int i = 0; i < b - c; ++i)
s += 'a' + c - 1;
for(int i = 0; i < a / b; ++i)
cout<<s;
for(int i = 0; i < a % b; ++i)
cout<<s[i];
cout<<endl;
}
return 0;
}
\(C.\)
Dado un conjunto de números \ (A \) , el conjunto de solicitados dividido en dos longitudes diferentes \ (S, \ T \) , \ (S \) tienen cada uno el mismo número, \ (T \) por El número es diferente, el número en \ (t \) también puede aparecer en \ (s \) , encuentre la longitud más grande posible
La idea inicial era una respuesta dicotómica, use \ (mapa \) para registrar el número de ocurrencias de cada número y luego vaya a \ (verificar \)
Más tarde \ (get \) tuvo una mejor idea
Con \ (X \) representa \ (A \) en \ (DISTINCT \) número de valores de
Use \ (y \) para indicar el número de ocurrencias del valor más frecuente en \ (a \)
\ (if \ x = y, \ ans = x - 1 \)
\ (de lo contrario, \ ans = min (x, \ y) \)
/*二分答案*/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define arrayDebug(a, l, r) for(int i = l; i <= r; ++i) printf("%d%c", a[i], " \n"[i == r])
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int DX[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 0, 1, 0, -1, -1, 1, 1, -1};
const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const double PI = acos(-1);
const double EPS = 1e-6;
using namespace std;
inline int read()
{
char c = getchar();
int ans = 0, f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {ans = ans * 10 + c - '0'; c = getchar();}
return ans * f;
}
int t, n, a[N];
map<int, int> mp;
bool check(int x)
{
int f1 = 0, f2 = 0;
set<int> st;
for(int i = 1; i <= n; ++i)
st.insert(a[i]);
for(int i = 1; i <= n; ++i) {
if(mp[a[i]] >= x) {
if(mp[a[i]] == x) st.erase(a[i]);
if(st.size() >= x) return 1;
st.insert(a[i]);
}
}
return 0;
}
int main()
{
t = read();
while(t--) {
mp.clear();
n = read();
for(int i = 1; i <= n; ++i) a[i] = read(), mp[a[i]]++;
int l = 0, r = n / 2;
int ans = 0;
while(l <= r) {
int mid = l + r >> 1;
//cout<<l<<' '<<r<<endl;
if(check(mid)) ans = mid, l = mid + 1;
else r = mid - 1;
}
printf("%d\n", ans);
}
return 0;
}
/*
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3
*/
/*good idea*/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define arrayDebug(a, l, r) for(int i = l; i <= r; ++i) printf("%d%c", a[i], " \n"[i == r])
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int DX[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 0, 1, 0, -1, -1, 1, 1, -1};
const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const double PI = acos(-1);
const double EPS = 1e-6;
using namespace std;
inline int read()
{
char c = getchar();
int ans = 0, f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {ans = ans * 10 + c - '0'; c = getchar();}
return ans * f;
}
int t, n;
map<int, int> mp;
int main()
{
t = read();
while(t--) {
mp.clear();
n = read();
int x = 0;
for(int i = 1; i <= n; ++i) {
int y = read();
mp[y]++;
x = max(x, mp[y]);
}
int ans = 0;
if(mp.size() == x) ans = x - 1;
else ans = min((int)mp.size(), x);
printf("%d\n", ans);
}
return 0;
}
/*
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3
*/
\(RE.\)
Dado un Sudoku correcto, como máximo se pueden modificar \ (9 \) dígitos para que sea \ (Anti-Sudoku \)
Sudoku satisfacción
- Cada línea no cuenta
- Cada columna no repite números
- Cada cuadrado de \ (3 \ times 3 \) no se superpone a los números
\ (Anti-Sudoku \)满足
- Se repiten al menos dos posiciones en cada línea.
- Cada columna repite al menos dos posiciones
- Cada cuadrado \ (3 \ times 3 \) tiene al menos dos posiciones que se repiten
La observación encontró que una posición debe modificarse en cada cuadrado, y las filas y columnas de estas posiciones no pueden repetirse. Puede escribir un método de búsqueda similar a \ (N \) Queen para escribir
Más tarde \ (obtener \) a una buena \ (idea \) , dado que se proporciona el Sudoku correcto, entonces solo necesitamos reemplazar cualquier número con otro número, por ejemplo, todos \ ( 3 \) reemplazado con \ (1 \)
/*dfs*/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define arrayDebug(a, l, r) for(int i = l; i <= r; ++i) printf("%d%c", a[i], " \n"[i == r])
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int DX[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 0, 1, 0, -1, -1, 1, 1, -1};
const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const double PI = acos(-1);
const double EPS = 1e-6;
using namespace std;
int t, n, vis[20][20];
char g[20][20];
int f = 0, cnt;
const int dx[] = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3};
const int dy[] = {0, 1, 2, 3, 1, 2, 3, 1, 2, 3};
int row[20], col[20];
inline int read()
{
char c = getchar();
int ans = 0, f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {ans = ans * 10 + c - '0'; c = getchar();}
return ans * f;
}
void out()
{
//puts("XCY");
for(int i = 1; i <= 9; ++i)
puts(g[i] + 1);
}
bool check()
{
map<int, int> mp;
for(int i = 1; i <= 9; ++i) {
int f = 0;
for(int j = 1; j <= 9; ++j) {
mp[g[i][j]]++;
if(mp[g[i][j]] > 1) {f = 1; break;}
}
if(!f) return 0;
mp.clear();
}
for(int i = 1; i <= 9; ++i) {
int f = 0;
for(int j = 1; j <= 9; ++j) {
mp[g[j][i]]++;
if(mp[g[j][i]] > 1) {f = 1; break;}
}
if(!f) return 0;
mp.clear();
}
for(int k = 1; k <= 3; ++k) {
for(int l = 1; l <= 3; ++l) {
int f = 0;
for(int i = (k - 1) * 3 + 1; i <= k * 3; ++i) {
for(int j = (l - 1) * 3 + 1; j <= l * 3; ++j) {
mp[g[i][j]]++;
if(mp[g[i][j]] > 1) {f = 1; break;}
}
if(f) break;
}
mp.clear();
if(!f) return 0;
}
}
return 1;
}
void dfs(int step)
{
//cout<<step<<endl;
if(f) return;
if(step > 9) {
cnt++;
if(check()) f = 1, out();
else return;
}
for(int i = 3 * (dx[step] - 1) + 1; i <= 3 * dx[step]; ++i) {
if(row[i]) continue;
for(int j = 3 * (dy[step] - 1) + 1; j <= 3 * dy[step]; ++j) {
if(col[j]) continue;
for(int k = 1; k <= 9; ++k) {
if(g[i][j] == k + '0') continue;
if(vis[i][j]) continue;
int temp = g[i][j];
vis[i][j] = 1;
g[i][j] = k + '0';
row[i] = 1, col[j] = 1;
dfs(step + 1);
if(f) return;
g[i][j] = temp;
vis[i][j] = 0;
row[i] = 0, col[j] = 0;
}
}
}
}
int main()
{
t = read();
while(t--) {
memset(vis, 0, sizeof(vis));
memset(col, 0, sizeof(col));
memset(row, 0, sizeof(row));
f = 0;
for(int i = 1; i <= 9; ++i)
scanf("%s", g[i] + 1);
dfs(1);
//cout<<cnt<<endl;
}
return 0;
}
/*
154873296
386592714
729641835
863725149
975314628
412968357
631457982
598236471
247189563
*/
/*replace 3 with 1*/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define arrayDebug(a, l, r) for(int i = l; i <= r; ++i) printf("%d%c", a[i], " \n"[i == r])
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int DX[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 0, 1, 0, -1, -1, 1, 1, -1};
const int MOD = 1e9 + 7;
const int N = 4e2 + 7;
const double PI = acos(-1);
const double EPS = 1e-6;
using namespace std;
int t, n;
char g[20][20];
inline int read()
{
char c = getchar();
int ans = 0, f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {ans = ans * 10 + c - '0'; c = getchar();}
return ans * f;
}
int main()
{
t = read();
while(t--) {
for(int i = 1; i <= 9; ++i)
scanf("%s", g[i] + 1);
for(int i = 1; i <= 9; ++i)
for(int j = 1; j <= 9; ++j)
if(g[i][j] == '3') g[i][j] = '1';
for(int i = 1; i <= 9; ++i)
puts(g[i] + 1);
}
return 0;
}