这次比赛的题目挺好,又是无限wa,这里写下ABCD的题解
传送门
主要思路: 找相同的时候,然后 /3 * 2 找最大值
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N = 100010;
int main(){
int T;
scanf("%d",&T);
while(T--){
int a,b;
scanf("%d%d",&a,&b);
if (a < b){
int temp = a;
a = b;
b = temp;
}
int res = 0;
if (a == b){
int x = a / 3;
res = x * 2;
if (a % 3 == 2) res ++;
}
else{
int x = a - b;
if (x >= b) res = b;
else{
res =(a - b);
int num = b-(a-b);
res += (num/3) * 2;
if(num%3 == 2) res ++;
}
}
printf("%d\n",res);
}
return 0;
}
主要思路: 扩展区间,最终计算区间的长度即可
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N = 100010;
int main(){
int T;
scanf("%d",&T);
while(T--){
int n, x , m;
scanf("%d%d%d",&n,&x,&m);
int xxx = x;
int yyy = x;
for (int i = 1; i <= m; i++){
int xx, yy;
scanf("%d%d",&xx,&yy);
if (xx <= yyy && yy >= xxx){
if (xx <= xxx){
xxx = xx;
}
if (yy >= yyy){
yyy = yy;
}
}
}
printf("%d\n",yyy - xxx + 1);
}
return 0;
}
主要思路: 首先他的对应步数也就是斜对角线,然后我们记录对应的斜对角线,然后去取0,1的数目,然后res += min(a,b) 即可
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N = 100010;
int a[200][200], ans[200][200];
int main(){
int T;
scanf("%d",&T);
while(T--){
memset(a,0,sizeof a);
int n, m;
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m;j ++){
scanf("%d",&ans[i][j]);
if (ans[i][j] == 1) a[i + j - 1][1] ++;
else a[i + j - 1][0] ++;
}
}
int res = 0;
for (int i = 1; i <= (n + m - 1)/2; i++){
int x = a[i][0] + a[n + m - i][0];
int y = a[i][1] + a[n + m - i][1];
res += min(x,y);
}
printf("%d\n",res);
}
return 0;
}
主要思路: 这题主要是规律题,首先要推出如果 gcd(x,y) == 1 推出 gcd(x + y, x * y ) == 1,然后我们找第一个最小的质因子即可(q^p),让他当做x
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N = 500010;
bool isPrime[12000010]; // 是否为素数
int Prime[12000010]; // 记录素数
int miPrime[12000010];
int a[N];
int b[N][2];
void eulerSieve(int n){
int num = 1;
memset(isPrime,true,sizeof isPrime);
for (int i = 2; i <= n; i++){
if (isPrime[i]) Prime[num++] = i, miPrime[i] = i;
for (int j = 1; j < num ; j ++){
if (i * Prime[j] > n)break;
isPrime[i*Prime[j]] = false;
miPrime[i*Prime[j]] = Prime[j];
if (i % Prime[j] == 0) break;
}
}
}
int main(){
eulerSieve(1e7);
int n;
scanf("%d",&n);
for (int i = 1; i <= n; i++){
scanf("%d",&a[i]);
}
for (int i = 1; i <= n; i++){
int t = miPrime[a[i]];
int x = a[i];
int num = 1;
while(a[i] % t == 0){
num *= t;
a[i] /= t;
}
if (x / num == 1){
b[i][0] = -1;
b[i][1] = -1;
}
else{
b[i][0] = num;
b[i][1] = x/num;
}
}
for (int i = 1; i<= n; i++){
printf("%d ",b[i][0]);
}
puts("");
for (int i = 1; i <= n; i++){
printf("%d ",b[i][1]);
}
puts("");
return 0;
}