Equation
\ [Time Limit: 3 s \
quad Memory Limit: 256 MB \] This practice a lot of questions, and even direct violence judge
view
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e5 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
bool ok(int a) {
for(int i=2; i*i<=a; i++) {
if(a%i == 0) return 1;
}
return 0;
}
bool che(int a, int b) {
return ok(a) && ok(b);
}
int main() {
int d;
scanf("%d", &d);
for(int i=1000000000; i>=d; i--) {
if(che(i, i-d)) return 0*printf("%d %d\n", i, i-d);
}
return 0;
}
Modulo Equality
\ [Time Limit: 3 s \
quad Memory Limit: 256 MB \] First \ (a [1] \) will become \ (b \) an element, then you can enumerate \ (a [1 ] \) into a number, this number is determined as \ (the X-\) , and then determine the legality and find out all the \ (the X-\) .
view
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 2e3 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
int a[maxn], b[maxn];
int s[maxn];
int main() {
scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++) scanf("%d", &a[i]);
for(int i=1; i<=n; i++) scanf("%d", &b[i]);
sort(a+1, a+1+n);
sort(b+1, b+1+n);
int ans = inf;
for(int i=1; i<=n; i++) {
int d = (b[i]-a[1]+m)%m;
for(int j=1; j<=n; j++) s[j] = (a[j]+d)%m;
sort(s+1, s+1+n);
int f = 1;
for(int j=1; j<=n; j++) {
if(s[j] != b[j]) {
f = 0;
break;
}
}
if(f) ans = min(ans, d);
}
printf("%d\n", ans);
return 0;
}
Long Beautiful Integer
\ [Time Limit: 3 s \
quad Memory Limit: 256 MB \] can be found in the final figure is certain \ (k \) is a loop section has been circulating, then we can consider before beginning a given numbers \ ( k \) position, with a look that \ (k \) bit bigger circulation can, if not, this \ (k \) digits plus one, and then start the cycle.
Because with \ (k \) a \ (9 \) to loop must be possible, so do not worry plus a variable number of digits after the issue.
view
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 2e5 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
char s[maxn], s1[maxn], s2[maxn];
bool ok() {
for(int i=1; i<=n; i++) {
if(s2[i] > s[i]) return true;
if(s2[i] < s[i]) return false;
}
return true;
}
int main() {
scanf("%d%d", &n, &m);
scanf("%s", s+1);
for(int i=1; i<=m; i++) s1[i] = s[i];
for(int i=1, j=1; i<=n; i++) {
s2[i] = s1[j];
j = j%m+1;
}
if(ok()) return 0*printf("%d\n%s\n", n, s2+1);
for(int i=1; i<=m; i++) s1[i] = s1[i]-'0';
s1[m]++;
for(int i=m; i>=1; i--) {
if(s1[i]>=10) {
s1[i] -= 10;
s1[i-1] += 1;
}
s1[i] += '0';
}
for(int i=1, j=1; i<=n; i++) {
s2[i] = s1[j];
j = j%m+1;
}
printf("%d\n%s\n", n, s2+1);
return 0;
}
Domino for Young
\ [Time Limit: 3 s \
quad Memory Limit: 256 MB \] thinking questions to kill me, but the idea that the problem is really elegant.
We put the entire map as an international board, international chessboard is black and white, then that is the answer must be \ (min \) (black plaid, white squares) , because I chose the lesser one, the other I You will be able to find adjacent to scrape out.
view
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e5 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
int main() {
scanf("%d", &n);
ll ans1 = 0, ans2 = 0;
for(int i=1, x; i<=n; i++) {
scanf("%d", &x);
if(i&1) ans1+=x/2, ans2+=(x+1)/2;
else ans2+=x/2, ans1+=(x+1)/2;
}
printf("%lld\n", min(ans1, ans2));
return 0;
}
K Integers
\[ Time Limit: 3 s\quad Memory Limit: 256 MB \]
留坑