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的概 ...
随机推荐
- 完美解决移动Web小于12px文字居中的问题
前几天的一篇博文:移动Web单行文字垂直居中的问题,提到了移动web里小于12px的文字居中异常的问题,最后还是改为12px才近乎解决了问题.但是有时候或许并不是那么乐观,你并不能将原本定为10px的 ...
- JavaScript图片轮播器
先贴上html的代码 <div class="ImgDiv"> <div class="Imgs" id="imgScroll&qu ...
- [Guava源码分析]ImmutableCollection:不可变集合
摘要: 我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3888557.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的 ...
- javascript Date 函数的坑
Javascrip中对日期的解析.格式化简直是混乱不堪,各种的坑,攻城狮们多小心. 1. 不要用 Date("yyyy-mm-dd") 构造函数解析字符串. IE.firefo ...
- PHP -Session 深入解剖 ① session的基本操作 【大成出品 --必是精品】。
Session的初步介绍 1 Session是服务器端技术,利用这个技术,服务器在运行时可以为每一个用户的不同浏览器(一个用户的不同浏览器将生成不同的session文件)创建一个其独享的sessio ...
- MinGW-64 安装
一.在mingw-w64官网下载mingw-w64在线安装包 二.点击mingw-w64进行安装,选择: Version:选最新版本 我这个是4.9.2 Architecture:x86_64 (64 ...
- oracle中的loop与while循环
Oracle中loop语句会先执行一次循环,然后再判断“exit when”关键字后面的条件表达式的值是true还是false,如果是true,那么将退出循环,否则继续循环. LOOP循环 语法如下l ...
- SOS.dll(SOS 调试扩展)
SecAnnotate.exe(.NET 安全批注器工具) SignTool.exe(签名工具) Sn.exe(强名称工具) SOS.dll(SOS 调试扩展) SqlMetal.exe(代码 ...
- vs2010旗舰版后,运行调试一个项目时调试不了,提示的是:无法使用“pc”附加到应用程序“webdev.webserver40.exe(PID:2260”
具体问题描述: vs2010旗舰版后,运行调试一个项目时调试不了,能编译,按ctrl+f5 可以运行,但是就是调试就不行,提示的是:无法使用“pc”附加到应用程序“webdev.webserver40 ...
- Python实战(2)
在安装python第三方插件库的时候遇到了这个错误 遇到这种问题可以”转战“国内的第三方镜像,问题便可迎刃而解.例如豆瓣镜像——http://pypi.douban.com/simple/ 先安装ea ...