水 A - Multiplication Table

不要想复杂,第一题就是纯暴力

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f; int main(void) {
int n, x; scanf ("%d%d", &n, &x);
int ans = 0;
for (int i=1; i<=n; ++i) {
if (x % i == 0) {
int y = x / i;
if (1 <= y && y <= n) ans++;
}
}
printf ("%d\n", ans); return 0;
}

素数 C - Vasya and Petya's Game

题意:在1~n之间猜一个数字x,可以问一些问题,x是否能整除y,问最少要问多少问题才能确定x

分析:我的方法就是把2~n的数字的质因数筛选出来,由此可以判断一些素数和不同素数的乘积。但是这样遗漏了平方数,比如能确定x整除3,结果可能是3也可能是9,所以最后把质因数的幂也放进答案

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std; const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
map<int, int> mp;
vector<int> ans; bool is_prime(int x) {
if (x == 2 || x == 3) return true;
if (x % 6 != 1 && x % 6 != 5) return false;
for (int i=5; i*i<=x; i+=6) {
if (x % i == 0 || x % (i + 2) == 0) return false;
}
return true;
} void factorize(int x) {
for (int i=2; i*i<=x; ++i) {
while (x % i == 0) {
if (!mp[x/i] && x / i != 1 && is_prime (x / i)) {
ans.push_back (x/i); mp[x/i] = 1;
}
x /= i;
}
}
if (x != 1) {
if (!mp[x] && is_prime (x)) {
ans.push_back (x); mp[x] = 1;
}
}
} int main(void) {
int n; scanf ("%d", &n);
mp.clear (); ans.clear ();
for (int i=n; i>1; --i) {
factorize (i);
} int sz = ans.size ();
for (int i=0; i<sz; ++i) {
int x = ans[i]; int t = x * x;
while (t <= n) {
if (!mp[t]) {
ans.push_back (t);
}
t *= x;
}
}
sort (ans.begin (), ans.end ());
sz = ans.size ();
printf ("%d\n", sz);
for (int i=0; i<sz; ++i) {
printf ("%d%c", ans[i], i == sz - 1 ? '\n' : ' ');
} return 0;
}

  

DP+抽屉原理 B - Modulo Sum

题意:问n个数字能否选出几个数字使得它们的和能整除m

分析:我觉得这是C题的难度。首先能想到同余模定理,对每个数字先取模。当n <= m时,用dp做,dp[i][j] 表示前i个数字,和取模后为j的方案有没有,那么就像01背包一样对与ai 取或不取,结果是dp[n][0]

当n > m时,官方题解是说弄个前缀和,根据抽屉原理,一定存在suml == sumr,那么sum (l + 1, r) == 0,也就是一定是YES了,这个我不会证明。戳开别人的代码发现可以用set来记录suml sumrd的值,如果那么根据上述一定是YES。

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
using namespace std; typedef long long ll;
const int N = 1e6 + 10;
const int M = 1e3 + 10;
const int INF = 0x3f3f3f3f;
int a[N];
bool dp[M][M];
set<int> S; int main(void) {
int n, m; scanf ("%d%d", &n, &m);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]); a[i] %= m;
} bool flag = false;
memset (dp, false, sizeof (dp));
if (n <= m) {
for (int i=1; i<=n; ++i) {
dp[i][a[i]] = true;
}
for (int i=2; i<=n; ++i) {
for (int j=0; j<m; ++j) {
dp[i][j] |= dp[i-1][j];
int pre = (j - a[i] + m) % m;
dp[i][j] |= dp[i-1][pre];
}
}
flag = dp[n][0];
}
else {
S.clear ();
int sum = 0;
for (int i=1; i<=n; ++i) {
sum = (sum + a[i]) % m;
if (S.find (sum) != S.end ()) flag = true;
S.insert (sum);
}
// flag = true;
} puts (flag ? "YES" : "NO"); return 0;
}

  

Codeforces Round #319 (Div. 2)的更多相关文章

  1. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  2. Codeforces Round #319 (Div. 1) B. Invariance of Tree 构造

    B. Invariance of Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/ ...

  3. Codeforces Round #319 (Div. 1) C. Points on Plane 分块

    C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...

  4. Codeforces Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学

    C. Vasya and Petya's Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  5. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  6. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  7. 构造+分块思想 Codeforces Round #319 (Div. 1) C

    http://codeforces.com/contest/576/problem/C 题目大意: 给你一个曼哈顿距离的图,然后要求你找到一个链,链穿了所有的点 然后要求这链的长度<=25*10 ...

  8. Codeforces Round #319 (Div. 2) E - Points on Plane

    题目大意:在一个平面里有n个点,点坐标的值在1-1e6之间,让你给出一个遍历所有点的顺序,要求每个点走一次,且 曼哈顿距离之和小于25*1e8. 思路:想了一会就有了思路,我们可以把1e6的x,y坐标 ...

  9. Codeforces Round #319 (Div. 2) D - Invariance of Tree

    Invariance of Tree 题目大意:给你一个有1-n组成的序列p,让你构造一棵树,如果节点a和b之间有一条边,则p[a]和p[b]之间也有一条边. 思路:没啥思路,看了题解菜爆. 我们可以 ...

  10. Codeforces Round #319 (Div. 2) D

    E A tree of size n is an undirected connected graph consisting of n vertices without cycles. Conside ...

随机推荐

  1. NAND flash坏区

    计算容量 厂家所说的4G指的是4 000 000 000字节,是按1000进制计算的,而电脑是按照1024进制计算的,所以标称为4G的NAND Flash理论容量是4 000 000 000 / 10 ...

  2. Parallels Desktop 设置win网络连接

    目的: 1 虚拟机中的win系统技能访问外网 2 可以和Mac系统互联 首先来实现1,很简单: 打开控制中心对应系统的设置 选择[硬件]->[网络] 源:设置共享网络 到此就达到1目的了: 现在 ...

  3. spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].

    项目加入FeignClient后再启动就报错,具体报错信息如下: org.springframework.core.annotation.AnnotationConfigurationExceptio ...

  4. gnss到底是什么呢

    GNSS Global Navigation Satellite System 全球卫星导航系统:提到这个很多人会不明白GNSS倒是是个啥东西呢,和北斗,GPS, GLONASS,Galileo系统有 ...

  5. RK3288 GPIO 输出问题【转】

    本文转载自:http://m.blog.csdn.net/jiangdou88/article/details/50158673 #define GPIO_BANK0              (0 ...

  6. dns服务器报错解决

    搭了个dns服务器,配置完毕老是报错,这里总结一下常见思路: ①关闭firewalld ②关闭selinux ③/var/named里面的配置文件所属用户组是否是root:named ④named.c ...

  7. 关于O_DIRECT的那些事儿

    很久之前落下的坑,一直没怎么记录-.- 一般地,如果在Linux内核中读写一个文件,其IO流程都需要经过Kernel内的page cache层次,如果程序员若想要使用自己开发的缓存系统,那么就可以在打 ...

  8. lucene Index Store TermVector 说明

    最新的lucene 3.0的field是这样的: Field options for indexingIndex.ANALYZED – use the analyzer to break the Fi ...

  9. Android Studio下载安装

    官方下载地址:https://developer.android.google.cn/studio#downloads 因为安卓自带的模拟器会比较慢一些,这里勾选去掉,我们使用夜神模拟器. 这里根据自 ...

  10. 理解Objective-C Runtime(四)Method Swizzling

    Objective-C对象收到消息之后,究竟会调用何种方法需要在运行期间才能解析出来.那你也许会问:与给定的选择子名称相应的方法是不是也可以在runtime改变呢?没错,就是这样.若能善用此特性,则可 ...