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的更多相关文章

  1. Codeforces 402D Upgrading Array:贪心 + 数学

    题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中 ...

  2. Codeforces 402B --耻辱的一题

    这题昨天晚上花了我1个小时50多分钟来搞,都没有搞定..后来看别人代码,直接暴力枚举第一个数的值来做..最多1000*1000的复杂度.当时怎么就没想到呢?还有为啥我的方法不对呢.. 暴力方法代码: ...

  3. 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( ...

  4. CodeForces - 402B Trees in a Row (暴力)

    题意:给定n个数,要求修改其中最少的数,使得这n个数满足ai + 1 - ai = k. 分析: 暴力,1000*1000. 1.这n个数,就是一个首项为a1,公差为k的等差数列.k已知,如果确定了a ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. UI3_ViewController初步

    // // AppDelegate.m // UI3_ViewController初步 // // Created by zhangxueming on 15/6/30. // Copyright ( ...

  2. FKP,一套全栈框架,基于react、webpack、koa1、babel

    FKP-REST是一套前后端分离,基于javascript的全栈实现,基于node的高性能,易部署性及javascript前后端语言的一致性,学习成本,时间成本及项目快速启动等等方面,FKP都是一种不 ...

  3. 7款经典炫酷的HTML5/jQuery动画应用示例及源码

    jQuery是一款普遍受前端开发者欢迎的Javascript框架,但是开发者貌似更关注jQuery开发的插件,海量的jQuery插件让前端开发者非常方便.HTML5的加入让jQuery这个家族更加丰富 ...

  4. 【leetcode】367. Valid Perfect Square

    题目描述: Given a positive integer num, write a function which returns True if num is a perfect square e ...

  5. for循环,你深刻理解了吗?

    前几天,有一个面试机会,去看了看,遇到一个认为不错的面试题!   过了几天看到csdn上说华为的一道面试题,看了下和我遇到的很相似!   我分享出来希望大家有帮助!   你真的深刻理解for循环了吗? ...

  6. Using Git Submodules

    NOTE: Following content is directly reprinted from http://patrickward.com/2013/01/09/using-git-submo ...

  7. centos6.5下的mysql5.6.30安装

    1.解压mysql tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  -C /usr/local mv mysql-5.6.30-linux-gli ...

  8. [Apache] 2.2与2.4版本在设置虚拟域名时的小差别

    Apache服务器配置虚拟步骤: 1.在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.conf中写入如下配置: #LoadModule ...

  9. 杂项一之js,<select>标签

    一.在aspx页面中实现 修改与删除页面的跳转 前台js部分: 在上部的js部分中写,根据传过来的id,来经行页面的跳转,并把id传过去 js部分就是实现了一个页面跳转的功能 (还有确认框confir ...

  10. winform INI文件操作辅助类

    using System;using System.Runtime.InteropServices;using System.Text; namespace connectCMCC.Utils{ // ...