BISTU-(1)-4-17-2016
A:贪心,遍历每次维护一个最便宜的价格,假如当前价格不如此前价格,就用此前价格购买当前数量的肉,每次更新最便宜的价格。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef struct Node {
int a;
int p;
int day;
}Node;
const int maxn = ;
int n;
Node orz[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n)) {
int minn = 0x7f7f7f;
int midx;
int ans = ;
for(int i = ; i <= n; i++) {
scanf("%d %d", &orz[i].a, &orz[i].p);
if(minn > orz[i].p) {
minn = orz[i].p;
ans += minn * orz[i].a;
}
else {
ans += minn * orz[i].a;
}
}
cout << ans << endl;
}
return ;
}
A
B:根据一个性质2^k=2*2^(k-1),每次计数不同幂的个数,假如有偶数个就向下一个数进位并划归为下一个数的个数(k/2个),直到k是奇数的时候,这时候举一次再更新。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef long long ll;
const int maxn = ;
int n;
ll dp[maxn]; int main() {
// freopen("in", "r", stdin);
int w;
while(~scanf("%d", &n)) {
memset(dp, , sizeof(dp));
for(int i = ; i <= n; i++) {
scanf("%d", &w);
dp[w]++;
}
ll ans = ;
for(int i = ; i < maxn; i++) {
dp[i+] += dp[i] / ;
ans += dp[i] % ;
}
printf("%I64d\n", ans);
}
return ;
}
B
C:利用fibonacci通项公式,先看对数的性质,loga(b^c)=c*loga(b),loga(b*c)=loga(b)+loga(c);假设给出一个数10234432,
那么log10(10234432)=log10(1.0234432*10^7)【用科学记数法表示这个数】=log10(1.0234432)+7;
log10(1.0234432)就是log10(10234432)的小数部分.
log10(1.0234432)=0.010063744(取对数所产生的数一定是个小数)
再取一次幂:10^0.010063744=1.023443198
取前4位,只需要将这个结果乘1000就可以了。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef long long LL;
int f[];
int n; void init() {
f[] = ;
f[] = ;
for(int i = ; i < ; i++) {
f[i] = f[i-] + f[i-];
}
} void solve() {
if(n < ) {
printf("%d\n", f[n]);
}
else {
int answer;
double ans = -0.5 * log10(5.0) + n * log10((+sqrt())/);
ans -= floor(ans);
ans = pow(, ans);
answer = int(ans * );
printf("%d\n", answer);
}
} int main() {
// freopen("in", "r", stdin);
init();
while(~scanf("%d", &n)) {
solve();
}
return ;
}
C
D:找出a数组里第k小的,再找出b数组里第m大的,假如a数组里k小的数都比b数组里m大的数小,那就满足条件。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int na, nb;
int k, m;
int a[maxn], b[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d %d", &na, &nb)) {
scanf("%d %d", &k, &m);
for(int i = ; i <= na; i++) scanf("%d", &a[i]);
for(int i = ; i <= nb; i++) scanf("%d", &b[i]);
sort(a+, a+na+);
sort(b+, b+nb+);
if(a[k] < b[nb-m+]) puts("YES");
else puts("NO");
} return ;
}
D
E:某人有n个朋友,这n个朋友有钱数m和关系s两个属性。问如何选择朋友,使得这些朋友之间s最大差距小于d并且钱数是最多。
可以用滑动窗口,将m从小到大,s从大到小排列,这时在一个队列里维护队首和队尾,假如队首和队尾的s差距≥d时,就把队尾扔掉队首入队否则就仅队首入队。此时更新一下当前最大值。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef long long ll;
typedef struct Node {
int m;
int s;
}Node;
const int maxn = ;
int n, d;
Node f[maxn]; bool cmp(Node a, Node b) {
if(a.m == b.m) return a.s > b.s;
return a.m < b.m;
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d %d", &n, &d)) {
for(int i = ; i <= n; i++) {
scanf("%d %d", &f[i].m, &f[i].s);
}
sort(f+, f+n+, cmp);
ll curans = ;
ll ans = ;
int front = ;
int tail = ;
while() {
if(front > n || tail > n) break;
if(f[tail].m - f[front].m >= d)
curans -= f[front++].s;
else curans += f[tail++].s;
ans = max(ans, curans);
}
printf("%I64d\n", ans);
}
return ;
}
E
F:先排序,知道第1个肯定和第n个离得最远,而和第2个离得最近。同理第n个和第1个离得最远,和第n-1个离得最近。固定这两个,接下来在中间找i,最远的话和1和n比,最近的话和i-1和i+1比。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int n;
int x[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n)) {
for(int i = ; i <= n; i++) {
scanf("%d", &x[i]);
}
sort(x+,x+n+);
printf("%d %d\n", abs(x[]-x[]), abs(x[]-x[n]));
for(int i = ; i < n; i++) {
printf("%d %d\n", abs(x[i]-x[i-]<abs(x[i]-x[i+]))?abs(x[i]-x[i-]):abs(x[i]-x[i+]),
(abs(x[i]-x[n])>abs(x[i]-x[]))?abs(x[i]-x[n]):abs(x[i]-x[]));
}
printf("%d %d\n", abs(x[n]-x[n-]), abs(x[]-x[n]));
}
return ;
}
F
G:按照从左到右的顺序,找一个子串。使得这个子串看成是上下左右移动步骤的时候可以走回远点。算算每一个子串里上下左右的个数就行了,假如上的次数等于下的次数,左的次数等于右的次数就说明可以回到原点。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int n;
char str[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n)) {
scanf("%s", str);
int ans = ;
int u, d, l, r;
for(int i = ; str[i]; i++) {
u = d = l = r = ;
for(int j = i; str[j]; j++) {
if(str[j] == 'U') u++;
if(str[j] == 'D') d++;
if(str[j] == 'L') l++;
if(str[j] == 'R') r++;
if(l == r && u == d) {
for(int k = i; k <= j; k++) {
printf("%c", str[k]);
}
printf("\n");
ans++;
}
}
}
printf("%d\n", ans);
}
return ;
}
G
BISTU-(1)-4-17-2016的更多相关文章
- stand up meeting 1/15/2016 && work of weekend 1/16/2016~1/17/2016
part 组员 工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 组内对生词卡片又重新进行了讨论:准备最后的发布和整个开发的整理 ...
- 2016 daily
2016.01.06 leetcode 切题数达到 200+,截止目前 137.虽然一年 63 题看似不多,但是 easy 的题目基本已经切完,质量 >> 数量(专注 leetcode,可 ...
- Microsoft SQL Server Version List [sqlserver 7.0-------sql server 2016]
http://sqlserverbuilds.blogspot.jp/ What version of SQL Server do I have? This unofficial build ch ...
- [linux]阿里云主机的免登陆安全SSH配置与思考
公司服务器使用的第三方云端服务,即阿里云,而本地需要经常去登录到服务器做相应的配置工作,鉴于此,每次登录都要使用密码是比较烦躁的,本着极速思想,我们需要配置我们的免登陆. 一 理论概述 SSH介绍 S ...
- Python标准模块--Unicode
1 模块简介 Python 3中最大的变化之一就是删除了Unicode类型.在Python 2中,有str类型和unicode类型,例如, Python 2.7.6 (default, Oct 26 ...
- 使用Expression实现数据的任意字段过滤(1)
在项目常常要和数据表格打交道. 现在BS的通常做法都是前端用一个js的Grid控件, 然后通过ajax的方式从后台加载数据, 然后将数据和Grid绑定. 数据往往不是一页可以显示完的, 所以要加分页: ...
- Nginx 访问日志轮询切割
Nginx 访问日志轮询切割脚本 #!/bin/sh Dateformat=`date +%Y%m%d` Basedir="/application/nginx" Nginxlog ...
- Python Logging模块的简单使用
前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...
- Oracle备库TNS连接失败的分析
今天在测试12c的temp_undo的时候,准备在备库上测试一下,突然发现备库使用TNS连接竟然失败. 抛出的错误如下: $ sqlplus sys/oracle@testdb as sysdba S ...
- SQL语句来查询今天、昨天、7天内、30天的数据,经典!
---恢复内容开始--- 今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0 昨天的所有数据:select * f ...
随机推荐
- 2014年全球SEO行业调查报告
前言: 1.该调查报告是MOZ每两年一度针对SEO行业的数据分析报告. 2.随着SEO的进化,该报告已不仅仅是SEO行业,今年的调查数据更多分析网络营销行业,可以称作"网络营销行业调查报告& ...
- js中常用数组方法concat join push pop slice splice shift
javascript给我们很多常用的 数组方法,极大方便了我们做程序.下面我们来介绍下常用的集中数组方法. 比如 concat() join() push() pop() unshift() shif ...
- ASP.NET MVC中几个运用技巧
1. Razor Helpers 的运用:例如,定义好 ViewBag.Message = "Welcome to ASP.NET MVC!";我要在界面上显示"Welc ...
- 比较IE6的不同之处,与IE8 IE11 比较
文档申明为 <!DOCTYPE html> IE6或者IE特有的一些东西 1.盒子模型 IE6:(使用 !DOCTYPE 声明指定 standards-compliant 模式) mar ...
- 编写更好的CSS
编写好的CSS代码能提升页面的渲染速度.本质上,一条规则都没有引擎解析的最快.MDN上将CSS选择符归拆分成四个主要类别,如下所示,性能依次降低. ID 规则 Class 规则 标签规则 通用规则 对 ...
- python模拟shell
import fileinput import readline raw_input(xxx) exec filepinput.input
- 客户端的数据来源:QueryString, Form, Cookie Request[]与Request.Params[]
在ASP.NET编程中,有三个比较常见的来自于客户端的数据来源:QueryString, Form, Cookie . 我们可以在HttpRequest中访问这三大对象. QueryString: 获 ...
- 通过 Mesos、Docker 和 Go,使用 300 行代码创建一个分布式系统
[摘要]虽然 Docker 和 Mesos 已成为不折不扣的 Buzzwords ,但是对于大部分人来说它们仍然是陌生的,下面我们就一起领略 Mesos .Docker 和 Go 配合带来的强大破坏力 ...
- Java 延时常见的几种方法
1. 用Thread就不会iu无法终止 new Thread(new Runnable() { public void run() { while (true) { test(); try { Thr ...
- DOS永久设置系统环境变量-WMIC
wmic Windows Management Instrumentation Command-line(Windows管理规范命令行) WMIC扩展WMI(Windows Management In ...