Codeforces 402A 402B 402C 402D
402A 直接暴力
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 2010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int main()
{
int k, a, b, v;
scanf("%d%d%d%d", &k, &a, &b, &v);
int ans = 0;
while(a > 0)
{
ans ++;
if(b >= k-1)
{
a -= k*v;
b = b-k+1;
}
else
{
a -= (b+1)*v;
b = 0;
}
}
printf("%d\n", ans);
return 0;
}
402B
修改尽量少的数字使数列成为公差为k的等差数列 (但是不能有负数)
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 2010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int num[1010], ans[1010], tem[1010];
int main()
{
int n, k;
memset(ans, 0, sizeof(ans));
scanf("%d%d", &n, &k);
for(int i = 0; i < n; ++ i)
{
scanf("%d", &num[i]);
tem[i] = num[i] - i*k;
}
sort(tem, tem+n);
int j = 0;
while(tem[j] <= 0) ++ j;
int now = tem[j], _max = 0, cnt = 0, cc = tem[j];
for(int i = j; i < n; ++ i)
{ if(now == tem[i]) ++ cnt;
else
{
if(cnt > _max)
{
_max = cnt;
cc = now;
}
now = tem[i];
cnt = 1;
}
}
if(cnt > _max)
{
_max = cnt;
cc = now;
}
printf("%d\n", n-_max);
for(int i = 0; i < n; ++ i)
{
if(cc+i*k > num[i]) printf("+ %d %d\n", i+1, cc+i*k-num[i]);
if(cc+i*k < num[i]) printf("- %d %d\n", i+1, num[i]-cc-i*k);
}
return 0;
}
402C 猜了一下 直接枚举一个最有可能的
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 2010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int main()
{
int t, n, p;
scanf("%d", &t);
while(t --)
{
scanf("%d%d", &n, &p);
int now = 2*n+p, st = 1, k = 1;
while(now--)
{
printf("%d %d\n", st, (st+k)%n == 0 ? n : (st+k)%n);
++ st;
if(st == n+1)
{
st = 1;
++ k;
}
}
}
return 0;
}
402D
数学加贪心
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 2010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int a[5010], cou[5010], pp[100000], m;
bool vis[100000];
struct node
{
int b[5050];
bool find(int x)
{
for(int i = 0; i < m; ++ i)
if(b[i] == x) return true;
return false;
}
};
node prime; int fi_pri()
{
int j = 0;
memset(vis, 1, sizeof(vis));
for(ll i = 2; i < 100000; ++ i)
if(vis[i])
{
pp[j++] = i;
for(ll j = i*i; j < 100000; j += i)
vis[j] = false;
}
return j;
} int gcd(int r, int l)
{
return l == 0 ? r : gcd(l, r%l);
} bool can(int i, int j)
{
int ans = 0;
for(int k = 0; k < j; ++ k)
if((i % pp[k] == 0) && (prime.find(pp[k])))
while(i % pp[k] == 0)
{
-- ans;
i /= pp[k];
}
else
while(i % pp[k] == 0)
{
++ ans;
i /= pp[k];
}
if(prime.find(i)) --ans;
if(ans < 0) return true;
return false;
} int f(int s, int j)
{
if(s == 1) return 0;
int i;
for(i = 0; i < j; ++ i)
if(s%pp[i] == 0)
break;
if(i != j && prime.find(pp[i]))
return f(s/pp[i], j) -1;
if(i != j)
return f(s/pp[i], j) +1;
if(prime.find(s))
return -1;
return 1;
} int main()
{
int asd = fi_pri(); int n, g;
scanf("%d%d", &n, &m);
scanf("%d", &a[0]);
g = cou[0] = a[0];
for(int i = 1; i < n; ++ i)
{
scanf("%d", &a[i]);
g = cou[i] = gcd(g, a[i]);
}
for(int i = 0; i < m; ++ i)
scanf("%d", &prime.b[i]);
for(int i = n-1; i >= 0; -- i)
if(can(cou[i], asd))
for(int j = 0; j <= i; ++ j)
{
a[j] /= cou[i];
cou[j] /= cou[i];
}
int ans = 0;
for(int i = 0; i < n; ++ i) ans += f(a[i], asd);
printf("%d\n", ans);
return 0;
}
Codeforces 402A 402B 402C 402D的更多相关文章
- Codeforces 402D Upgrading Array:贪心 + 数学
题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中 ...
- Codeforces 402B --耻辱的一题
这题昨天晚上花了我1个小时50多分钟来搞,都没有搞定..后来看别人代码,直接暴力枚举第一个数的值来做..最多1000*1000的复杂度.当时怎么就没想到呢?还有为啥我的方法不对呢.. 暴力方法代码: ...
- CodeForces 402D Upgrading Array (数学+DP)
题意:给出一个数列,可以进行一种操作将某一个前缀除去他们的gcd,有一个函数f(x),f(1) = 0 , f(x) = f(x/p)+1,f(x) = f(x/p)-1(p是坏素数), 求 sum( ...
- CodeForces - 402B Trees in a Row (暴力)
题意:给定n个数,要求修改其中最少的数,使得这n个数满足ai + 1 - ai = k. 分析: 暴力,1000*1000. 1.这n个数,就是一个首项为a1,公差为k的等差数列.k已知,如果确定了a ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- python基础:三层循环
三层循环基本演示: break_flag = False #标记1 break_flag2 = False #标记2 break_flag3 = False #标记3 while not break_ ...
- ubuntu 12.04 安装 codeblock 12.11
原文地址:http://qtlinux.blog.51cto.com/3052744/1136779 参考文章:http://blog.csdn.net/dszsy1990/article/det ...
- (转)对DotNet分布式应用搭建的考虑
设计前的考虑和准备工作 1 对业务需求的理解重要性远远胜于对技术架构的理解 2 架构包含技术架构和业务架构 3 没有万能和通用的架构,只有符合自身业务需求的架构 4 架构本身的复杂性要截至在架构设计阶 ...
- Bootstrap Paginator 分页 demo.
效果如下: 需要的引用以下内容 bootstrap2 http://cnbootstrap.com/ bootstrap-paginator v0.5 主页 http://bootstrappagin ...
- 设置datagridview中button按钮的背景颜色
问题:DataGridViewButtonColumn()在datagridview中创建按钮列,如何设置按钮的背景颜色(不是单元格的背景颜色). 回答:可以在dataGridView1_CellPa ...
- C++安装失败解决办法
法一:删除注册表中的HKY_LOCAL_MACHINE\\SYSTEM|ControlSet001\\Services\\VSS,卸载重装.法二:点击 setup目录下的 wpie15.exe .. ...
- 使用awstats分析iis站点的日志
环境:win7 + iis7 + perl(ActivePerl-5.20.1.2000) + awstats 7.3 一.找到iis日志所在目录 建议全部都打勾 二.安装perl AWStats是p ...
- 封装cookie
function cookie(name,value,expires){ switch(typeof value){ case 'string': //设置 var exp=''; if(expire ...
- Cassandra1.2文档学习解读计划——为自己鼓劲
最近想深入研究一下Cassandra,而Cassandra没有中文文档,仅有的一些参考书都是0.7/0.6版本的.因此有个计划,一边学习文档(地址:http://www.datastax.com/do ...
- CentOS如何分区
安装Linux CentOS时,需要在硬盘建立CentOS使用的分区,在大多情况下,至少需要为CentOS建立以下3个分区. (1)/boot分区(不是必须的):/boot分区用于引导系统,它包含了操 ...