http://acm.uestc.edu.cn/#/problem/show/1544

考虑一下2、2、2这样的情况。答案应该是n / 2

如果只选一个的情况下,对答案的贡献是正的,但是这里有三个,也就是我们统计了3 * n / 2,统计多了。

那么对于任选两个数的情况,有三种,(2, 2) * 3,分别都是不同位置的2,

/**************************************/

我做的时候是发现,先讨论只有

2、2的情况,也就是只有两个数的时候,ans = 0,这个时候,先模拟上面的,只选一个,答案是2 * n / 2

那么枚举两个数的情况,应该就是要ans -= 2 * n / (lcm(2, 2))

要减2倍,不然答案不是0.

/**************************************/

那么上面也是,有三种(2, 2)的情况,ans -= 3 * 2 * n / (lcm(2, 2))

那么现在是-3 * n / (lcm(2, 2))

然后还有一种的就是枚举三个的情况,要使答案是n / 2,那么应该加上4 * n / (lcm(2, 2))

然后得到的规律是1 << (sel - 1),sel是选的数字个数。

完全是瞎比比的,数学不好。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
int n, has;
const int maxn = + ;
int arr[maxn];
LL ans;
LL LCM(LL a, LL b) {
return a / __gcd(a, b) * b;
}
void dfs(int cur, int sel, LL theLcm) {
if (theLcm > n) return;
if (cur == has + ) {
if (!sel) return;
if (sel & ) {
ans += ( << (sel - )) * (n / theLcm);
} else {
ans -= ( << (sel - )) * (n / theLcm);
}
return;
}
dfs(cur + , sel, theLcm);
dfs(cur + , sel + , LCM(theLcm, arr[cur]));
}
void work() {
ans = ;
scanf("%d%d", &n, &has);
for (int i = ; i <= has; ++i) {
scanf("%d", &arr[i]);
}
dfs(, , );
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

还有就是数据中没有15个大质数这样的情况,数据比较弱。

UESTC - 1544 当咸鱼也要按照基本法 组合数学 容斥原理的更多相关文章

  1. 【容斥原理】CDOJ - 1544 - 当咸鱼也要按照基本法

    众所周知zhu是一个大厨,zhu一直有自己独特的咸鱼制作技巧. tang是一个咸鱼供应商,他告诉zhu在他那里面有NN条咸鱼(标号从1到N)可以被用来制作. 每条咸鱼都有一个咸鱼值KiKi,初始时所有 ...

  2. 【cdoj 1544】当咸鱼也要按照基本法

    [题目链接]:http://acm.uestc.edu.cn/#/problem/show/1544 [题意] [题解] 容斥原理题; 1..(2^m)-1枚举 设k为其二进制形式中1的个数; k为奇 ...

  3. cdoj1325卿学姐与基本法

    地址:http://acm.uestc.edu.cn/#/problem/show/1325 题目: 卿学姐与基本法 Time Limit: 2000/1000MS (Java/Others)     ...

  4. B - 卿学姐与基本法 (离散化+成段更新+区间求和)

    卿学姐与基本法 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  5. ACM:UESTC - 649 括号配对问题 - stack

      UESTC - 649  括号配对问题 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu ...

  6. UESTC 1015 Lweb and pepper --前,后缀最值

    题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...

  7. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

  8. UESTC 1851 Kings on a Chessboard

    状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...

  9. UESTC 30 最短路,floyd,水

    最短路 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Statu ...

随机推荐

  1. ansible 文件模块,很实用

    摘自: http://blog.csdn.net/kellyseeme/article/details/50545521

  2. Android5.0 CheckBox颜色修改

    Android5.0开始,CheckBox带有material design动画效果,其默认的样式如下图所示: 可以看到,在上图中,CheckBox的边框为灰色,当被选中后,填充色为绿色. 那么如果我 ...

  3. codeforces A. Black-and-White Cube 解题报告

    题目链接:http://codeforces.com/problemset/problem/323/A 题目意思:给定值 k ,需要输出 k 个 k 行 k 列的单位立方体各表示什么颜色(或者是黑色或 ...

  4. 继续servlet理论篇

    唉,毕业是件很麻烦的事情,实习也是一件很郁闷的事情,现在公司很注重基础,所以 所以还要看java,不过,我年轻,我有激情.来吧,来着不惧,说这话,有些心虚. HttpServlet类中所提供的doGe ...

  5. luogu 3389 【模板】高斯消元

    大概就是对每一行先找到最大的减小误差,然后代入消元 #include<iostream> #include<cstdio> #include<cstring> #i ...

  6. python 复制文件流程

    例子代码: [root@master script]# vim copy_file.py #!/usr/bin/python # -*- coding:utf-8 -*- old_file_name ...

  7. UOJ309 UNR #2 排兵布阵

    包含不小于$\sqrt n$列的只有不大于$\sqrt n$行,修改时这些行打标记,否则暴力更新,操作一列的时候暴力更新这些行.合并没啥影响直接搞就是了.更新需要访问位置,感觉必须用哈希表,并不是特别 ...

  8. web集群时代

    随着业务的不断增加,我们的单台服务器承受不住需求,那么我们就需要对此进行伸缩,有两种维度,一种是纵向的也就是增大该台服务器的硬件,再者就是加新服务器与之前的机器组成集群对外提供服务,我们都知道前者是有 ...

  9. A - Alyona and Numbers

    Description After finishing eating her bun, Alyona came up with two integers n and m. She decided to ...

  10. ** Error in `./g2o_viewer': realloc(): invalid pointer:

    问题: defe@defe-Precision-Tower-3620:~/project/Demo/UseG2OforPoseGraph/useg2oforposegraph$ ./g2o_viewe ...