NOIP2023模拟1联测22 黑暗料理

编程入门 行业动态 更新时间:2024-10-23 15:19:12

NOIP2023模拟1<a href=https://www.elefans.com/category/jswz/34/1761362.html style=联测22 黑暗料理"/>

NOIP2023模拟1联测22 黑暗料理

NOIP2023模拟1联测22 黑暗料理

题目大意

自己看

思路

  • 两个数相加能够产生质数的情况就是:1+1 或者 偶数+质数

    那么 1 1 1 不能保留超过一个

  • 建一个图,原点连向所有奇数点,所有偶数点连向汇点,奇数点和偶数点的和为奇数的就相连

    那么答案就是隔断原、汇两点的最小割。

  • 判断质数用Miller_Rabin

code

#include <bits/stdc++.h>
#define fu(x , y , z) for(int x = y ; x <= z ; x ++)
#define fd(x , y , z) for(int x = y ; x >= z ; x --)
#define LL long long 
using namespace std;
const int N = 755;
int n , a[N * N * 2] , p[5] = {2 , 3 , 5 , 7 , 11} , cnt , ans , ans1 , hd[N * N * 2] , pos1[N] , pos2[N * N * 2] , cx1 , cx2 , cx[N] , cy[N] , vis[N];
struct E {int to , nt;
} e[N * N * 4];
void add (int x , int y) { e[++cnt].to = y , e[cnt].nt = hd[x] , hd[x] = cnt; }
bool cmp (int x , int y) { return a[x] > a[y]; }
LL ksm (LL x , LL y , LL mod) {if (!y) return 1;LL z = ksm (x , y / 2 , mod);z = z * z % mod;if (y & 1) z = z * x % mod;return z;
}
bool ck (LL x , LL y) {LL mod = x - 1 , xx;if (ksm (y , mod , x) != 1)return 0;do {xx = ksm (y , mod / 2 , x);if (xx != 1 && xx != x - 1)return 0;mod >>= 1;} while (mod % 2 == 0 && xx == 1);return 1;
}
bool mb (LL x) {if (x == 1)return 0;if (x == 2 || x == 3 || x == 5 || x == 7 || x == 11)return 1;fu (i , 0 , 4) {if (!ck (x , p[i])) return 0;}return 1;
}
bool find (int x) {int y;for (int i = hd[x] ; i ; i = e[i].nt) {y = e[i].to;if (vis[y]) continue;vis[y] = 1;if (!cy[y] || find (cy[y])) {cx[x] = y , cy[y] = x;return 1;}}return 0;
}
int main () {freopen ("cooking.in" , "r" , stdin);freopen ("cooking.out" , "w" , stdout);int T , flg;scanf ("%d" , &T);while (T --) {scanf ("%d" , &n);fu (i , 1 , n)scanf ("%d" , &a[i]);cnt = ans1 = ans = flg = cx1 = cx2 = 0;fu (i , 1 , n * n * 2) hd[i] = cx[i] = cy[i] = 0;fu (i , 1 , n) {if (a[i] & 1) {if (a[i] == 1) {if (!flg) flg = 1;else {ans1 ++;continue;}}pos1[++cx1] = i;}         elsepos2[++cx2] = i;}fu (i , 1 , cx1) {fu (j , 1 , cx2) {if (a[pos1[i]] == 51 && a[pos2[j]] == 38) {ans ++;ans --;}if (mb (a[pos1[i]] + a[pos2[j]])) {add (i , cx1 + j);// cout << a[pos1[i]] << " " << a[pos2[j]] << "\n";}}}// exit (0);fu (i , 1 , cx1) {if (cx[i]) continue;fu (j , 1 , cx2) vis[j + cx1] = 0;ans += find (i);}// cout << ans;/printf ("%d\n" , n - ans1 - ans);}return 0;
}

更多推荐

NOIP2023模拟1联测22 黑暗料理

本文发布于:2023-12-03 20:37:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1657389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:联测   料理   黑暗

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!