Codeforces Round #330 (Div. 2)
C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了。
/************************************************
* Author :Running_Time
* Created Time :2015/11/8 星期日 22:41:11
* File Name :A.cpp
************************************************/ #include <bits/stdc++.h>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
int a[110][220]; int main(void) {
int n, m; cin >> n >> m;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=2*m; ++j) cin >> a[i][j];
}
int ans = 0;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=2*m-1; j+=2) {
if (a[i][j] == 1 || a[i][j+1] == 1) ans++;
}
}
cout << ans; //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}
题意:n个数字分成n/k块,每块有k个数字,问n个数字,其中每一块第一个数字不是b[i]且该k个数字组成的数字能整除a[i]的方案数
分析:直接说方法吧,最大的数字比如999999除以a[i]就是所有在99999范围内a[i]的倍数,然后减去以b[i]开头的那些数字就是一块的方案数。我脑子没转过弯,用乘法一个一个乘,当然超时,怎么没想到除呢,还想用DP? (a[i] < 10 ^ k),(卒
/************************************************
* Author :Running_Time
* Created Time :2015/11/8 星期日 22:41:14
* File Name :B.cpp
************************************************/ #include <bits/stdc++.h>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
ll a[N], b[N]; ll get_max(int k) {
ll ret = 0;
for (int i=1; i<=k; ++i) {
ret = ret * 10 + 9;
}
return ret;
} ll get_b_max(ll x, int k) {
ll ret = x;
for (int i=1; i<k; ++i) {
ret = ret * 10 + 9;
}
return ret;
} ll get_b_min(ll x, int k) {
ll ret = x;
for (int i=1; i<k; ++i) {
ret = ret * 10;
}
return ret;
} ll multi_mod(ll a, ll b) {
ll ret = 0;
while (b) {
if (b & 1) {
ret += a;
if (ret >= MOD) ret -= MOD;
}
b >>= 1; a <<= 1;
if (a >= MOD) a -= MOD;
}
return ret;
} int main(void) {
int n, k; cin >> n >> k;
int m = n / k;
for (int i=1; i<=m; ++i) {
cin >> a[i];
}
for (int i=1; i<=m; ++i) {
cin >> b[i];
}
ll ans = 1, mx = get_max (k);
for (int i=1; i<=m; ++i) {
ll cnt = mx / a[i] + 1;
ll bmn = get_b_min (b[i], k), bmx = get_b_max (b[i], k);
cnt -= (bmx / a[i] - bmn / a[i]);
if (bmn % a[i] == 0) cnt--;
ans = multi_mod (ans, cnt);
}
cout << ans << endl; //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}
Codeforces Round #330 (Div. 2)的更多相关文章
- Codeforces Round #330 (Div. 1) A. Warrior and Archer 贪心 数学
A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594 ...
- Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...
- Codeforces Round #330 (Div. 2)D. Max and Bike 二分 物理
D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/probl ...
- Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...
- Codeforces Round #330 (Div. 2) A. Vitaly and Night 暴力
A. Vitaly and Night Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/p ...
- 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) B题
题意: 这道英文题的题意稍稍有点复杂. 找长度为n的数字序列有多少种.这个序列可以分为n/k段,每段k个数字.k个数可以变成一个十进制的数Xi.要求对这每n/k个数,剔除Xi可被ai整除的情况,剔除X ...
- 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) Vitaly and Night
题意:给你很多对数,要么是0要么是1.不全0则ans++. 思路即题意. #include<cstdio> #include<cstring> #include<iost ...
- Codeforces Round #330 (Div. 2) B. Pasha and Phone
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #330 (Div. 2) B 容斥原理
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- java笔记--策略模式和简单工厂模式
策略模式: --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3884781.html "谢谢-- 为什么使用:策略模式主要用于 ...
- Xcode 5.0.2 下载地址
下载地址:http://adcdownload.apple.com/Developer_Tools/xcode_5.0.2/xcode_5.0.2.dmg command_line_tools_os_ ...
- 删除右键ATI CATALYST(R) Control Center的方法
http://share.weiyun.com/c47530d3e44ea15b606d4ba6f1b00a28
- nginx: [emerg] getpwnam(“www”) failed
在配置nginx 时提示如下错误时:nginx: [emerg] getpwnam(“www”) failed 解决方案一 在nginx.conf中 把user nobody的注释去掉既可 解决方案二 ...
- 三款SDR平台对比:HackRF,bladeRF和USRP
这篇文章是Taylor Killian今年8月发表在自己的博客上的.他对比了三款平价的SDR平台,认为这三款产品将是未来一年中最受欢迎的SDR平台.我觉得这篇文章很有参考价值,简单翻译一份转过来.原文 ...
- 暑假热身 D. 条形码设计
校ACM队准备筹划向学校批请一个专用机房.但是为了防止它变成公用机房,FL建议采用刷卡进入的办法,她设计了一种条形码,每人都对应一个.这种大小为2*n的条形码由以下三种元素构成:1*2.2*1.2*2 ...
- Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载
Shell脚本中判断输入参数个数的方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了Shell脚本中判断输入参数个数的方法,使用内置变量$#即可实现判断输入了多少个参数 ...
- 【Other】推荐点好听的钢琴曲
2013-12-13 16:19 匿名 | 浏览 138977 次 音乐钢琴 推荐点好听的钢琴曲,纯音乐也可以thanks!!! 2013-12-14 19:34 网友采纳 热心网友 巴洛克:帕海贝尔 ...
- Java for LeetCode 165 Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- Java for LeetCode 039 Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...