水 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. ExtJs学习笔记(1)---ExtJs安装及其使用

    从官网下载了ExtJs的3.2版本号的SDK,包括了代码依赖的具体说明.文档.范例和其它文件.当中,adapter和resources文件是Ext正常执行所必须的,其它的仅在开发过程中使用到. Ada ...

  2. Ctrl+Enter 选中文本提交

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <bod ...

  3. 如何解决Windows的端口占用问题?

    已知某应用在启动时会创建服务套接字,并将其绑定至端口8888,然而端口8888已被占用,如何解除占用? 以下为解决方案: 在cmd中运行netstat -ano|findstr 8888,其中的参数8 ...

  4. java包和javax包的区别

    基本类库和扩展类库 一般的lang,util都放在java.包 servlet放在javax包 以前sun把java中的叫核心库,把javax中的叫扩展库.现在sun已经把java和javax中的都叫 ...

  5. Delphi ActiveForm发布全攻略

    论坛上很多朋友(也包括我)提到ActiveForm的发布问题,都没有得到很好的解决.下面是本人开发ActiveForm的一点经验,拿出来跟大家分享,开发环境为 Win2000Server,IIS5.0 ...

  6. 秒懂单链表及其反转(reverse)

    什么是链表,这种数据结构是由一组Node组成的,这群Node一起表示了一个序列.链表是最普通,最简单的数据结构(物理地址不连续),它是实现其他数据结构如stack, queue等的基础. 链表比起数组 ...

  7. [RK3288][Android6.0] 调试笔记 --- pmu(rk818)寄存器读写【转】

    本文转载自:http://blog.csdn.net/kris_fei/article/details/76919134 Platform: Rockchip OS: Android 6.0 Kern ...

  8. Spring Boot2.0+Redis+Ehcache实现二级缓存

    EHCache 本地缓存 Redis 分布式缓存(可以共享) 一级 Redis 二级Ehcache    当redis挂了 有备胎 反之: 先走本地,本地没有再走网络  尽量少走Redis  效率会高 ...

  9. maven配置本地仓库和国内镜像仓库,解决国内访问国外中央仓库速度过慢问题

    Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 1.配置本地仓库   打开conf文件夹下面的setting.xml文件 红色方框为配置本地仓 ...

  10. oracle监听器启动,实例启动

    1,su - oracle登录oracle用户 2,sqlplus / as sysdba登录oracle 3,show parameter service_names; 若正常输出servicena ...