当前位置: 首页 > news >正文

Exam in MAC [容斥]

题意

思路

正难则反

反过来需要考虑的是:

(1) 所有满条件一的(x,y)有多少对:

x = 0 时,有c+1对   x = 1 时,有c对  ......  x = c 时,有1对

以此类推 一共有 (c+2)(c+1)/2 对

(2) 符合 x + y ∈ S的有多少对:

那就是x + y = ai  对 x = 0 而言 y有固定的一种取值ai

但是要保证的是 y <= c 所以有 c - x + 1

而x: 0->ai 所以对每一个ai有 ai/2 + 1种

(3) 符合 y - x ∈ S 的有多少对:

y - x = ai 

那么 y = ai + x < c

y ∈ [x,c-a[i]] 而x是从0开始的 所以每一个ai 都有 c - a[i] + 1 种的情况

(4) 符合 (2) + (3)的有多少对:

x + y = ai

y - x = aj

y = (ai + aj) / 2 所以要保证的是只有同奇偶性 才有这种情况

比如 奇数有{1,3,5}那么其实是C(2,3) + 3 那就是 n(n-1)/2 + n = n(n+1)/2

答案就是 odd(odd+1) / 2 + even(even+1) / 2

(LAST ) ALL IN ALL

根据容斥定理 res = (1) - (2) - (3) + (4)

#include<iostream>
#include<cstdio>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF = 1e18 + 10;
const int N = 1e5 + 10;
const int M = 1e7 + 10;// 节点数量 3e6就够了是为什么?
const int mod = 1e9 + 7;
int n, m, k, x, now, ans;
int qcal(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a % mod; b >>= 1; a = a * a % mod; } return res; }
int a[N], b[N];
bool is_prime(int n){if (n < 2) return false; for (int i = 2; i <= n / i; i++){if (n % i == 0){return false;}}return true;}
void gzy()
{int c;cin >> n >> c;int ans = (1 + c) * (2 + c) / 2;int odd = 0,even = 0;for(int i = 1;i <= n;i ++){cin >> x;ans -= x / 2 + 1;ans -= (c - x + 1);if(x % 2 == 0) odd ++;else even ++;}ans += (odd + 1) * odd / 2;ans += (even + 1) * even / 2;cout << ans << endl; 
} signed main()
{int _ = 1; cin >> _;while (_--) gzy();return 0;
}
// /**
//  *  ┏┓   ┏┓+ +
//  * ┏┛┻━━━┛┻┓ + +
//  * ┃       ┃
//  * ┃   ━   ┃ ++ + + +
//  *  ████━████+
//  *  ◥██◤ ◥██◤ +
//  * ┃   ┻   ┃
//  * ┃       ┃ + +
//  * ┗━┓   ┏━┛
//  *   ┃   ┃ + + + +Code is far away from  
//  *   ┃   ┃ + bug with the animal protecting
//  *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
//  *   ┃  	    ┣┓
//  *    ┃        ┏┛
//  *     ┗┓┓┏━┳┓┏┛ + + + +
//  *    ┃┫┫ ┃┫┫
//  *    ┗┻┛ ┗┻┛+ + + +
//  */

http://www.lryc.cn/news/318045.html

相关文章:

  • Java 学习和实践笔记(36):接口(interface)
  • Elastic Stack--10--QueryBuilders UpdateQuery
  • 腾讯云服务器CVM_云主机_云计算服务器_弹性云服务器
  • Java八股文(Spring Boot)
  • ts文件怎么无损转换mp4?这样设置转换模式~
  • 如何在Windows 10上打开和关闭平板模式?这里提供详细步骤
  • 介绍kafka核心原理及底层刷盘机制,集群分片机制,消息丢失和重复消费有对应的线上解决方案
  • 基于Python的中医药知识问答系统设计与实现
  • QT 如何防止 QTextEdit 自动滚动到最下方
  • 【C/C++ 学习笔记】指针
  • 【Node.js从基础到高级运用】十二、身份验证与授权:JWT
  • 蓝桥杯刷题|01入门真题
  • Python Django相关解答
  • 在Linux/Ubuntu/Debian中使用7z压缩和解压文件
  • 设计一些策略和技术来防止恶意爬虫
  • elasticsearch常见问题:xpack.security.transport.ssl、unknown setting [node.master]
  • LLM(大语言模型)——Springboot集成文心一言、讯飞星火、通义千问、智谱清言
  • 什么是堆?什么是栈?
  • 【镜像转存】利用交互式学习平台killercoda转存K8S镜像至Docker私人仓库
  • ov多域名SSL数字证书1200元一年送一月
  • MySQL 系统变量查看与设置(System Variables Configuration)
  • 【Docker】apache 容器化部署
  • 基于element-plus +腾讯云COS实现图片上传
  • Kafka模拟器产生数据仿真-集成StructuredStreaming做到”毫秒“级实时响应StreamData落地到mysql
  • IDEA如何删除git最新一次远程提交
  • 什么是单向数据流
  • Qt 线程池 QThreadPool
  • 【兔子机器人】实现从初始状态到站立
  • ImportError: cannot import name ‘open_filename‘ from ‘pdfminer.utils‘已搞定
  • 一文解决Word中公式插入问题(全免费/latex公式输入/texsWord)