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. 用margin还是用padding?(3)—— 负margin实战

    看过一篇文章是关于我知道你不知道的负Margin,里面对margin做了总结: 当margin四个值都为正数值的话,那么margin按照正常逻辑同周围元素产生边距.当元素margin的top和left ...

  2. hdu 1236 排名(排序)

    题意:按成绩排序 思路:排序 #include<iostream> #include<stdio.h> #include<string.h> #include< ...

  3. Vijos P1794 文化之旅

    标签:                                         搜索图结构 最短路                                    NOIP普及组2012 ...

  4. codeforces 701E E. Connecting Universities(树的重心)

    题目链接: E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes i ...

  5. I.MX6 Surfaceflinger 机制

    /**************************************************************************** * I.MX6 Surfaceflinger ...

  6. BZOJ_3566_[SHOI2014]概率充电器_概率+树形DP

    BZOJ_3566_[SHOI2014]概率充电器_概率+树形DP Description 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品——概率充电器: “采用全新纳米级加工技 ...

  7. [WC 2006] 水管局长

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2594 [算法] 首先离线 , 将删边操作转化为倒序加边 假设我们已经维护出了一棵最小 ...

  8. 解决最近windows版本Node.js中npm出现的“Error: ENOENT, stat 'C:\Users\UserName\AppData\Roaming\npm”的问题

    (转载请注明出处,from www.cnblogs.com/xdxer) 问题可能如下所示 解决方案: 在 'C:\Users\UserName\AppData\Roaming\‘ 下手动的增加一个文 ...

  9. live555 基本类之间的关系

    live555 中存在这5个最基本的类.每个类中都拥有一个BasicUsageEnvironment. 这是这几个类之间的相互关系.   MediaSession可以拥有多个subsession.

  10. 1.9 Hive常见属性配置

    一.Hive数据仓库位置配置 1. # Hive数据仓库位置配置: 默认位置(hive根目录): /user/hive/warehouse 注意事项: *在仓库目录下,没有对默认的数据库default ...