水 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. Android Camera系统深入理解

    1. Android Camera系统架构 http://blog.csdn.net/myarrow/article/details/8489674

  2. 组合式+迭代式+链式 MapReduce

    1.迭代式mapreduce 一些复杂的任务难以用一次mapreduce处理完成,需要多次mapreduce才能完成任务,例如Pagrank,Kmeans算法都需要多次的迭代,关于mapreduce迭 ...

  3. 使用C++11的thread取代QThread

    因为在做的工程项目里使用了Qt,而实际上不涉及到屏幕显示,工程代码里使用了QThread,且没有使用Qt核心的信号与槽,为了以后移植准备使用更加通用的C++11 stl中的thread取代QThrea ...

  4. lc.exe 已退出 代码为 -1

    地址:http://jingyan.baidu.com/article/91f5db1bd0ace31c7f05e321.html

  5. oracle服务丢失的处理方法之OracleServiceORCL不存在示例

    oracle服务是oracle数据库的重要组成部分,下面就教您oracle服务丢失的处理方法,如果您之前遇到过oracle服务丢失的问题,不妨一看. 今天发现数据库服务器上的所有oracle服务都丢失 ...

  6. HDU 3714/UVA1476 Error Curves

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  7. 通过powershell操作eventlog

    relevant command list ~\Desktop> (Get-Command Write-EventLog).Parameters Key Value --- ----- Warn ...

  8. 【矩阵---求A的1到N次幂之和】

    引例: Matrix Power Series: 题目大意,给定矩阵A,求A^+A^+A^+...A^N. 题解:已知X=a,可以通过以下矩阵求出ans=a^+a^+...a^=矩阵^(n+)后右上格 ...

  9. HBase之四--(1):Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  10. Vue中devtools安装使用

    vue.js的devtools安装 安装 1.github下载地址:https://github.com/vuejs/vue-devtools 2.下载好后进入vue-devtools-master工 ...