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

  1. stand up meeting 1/15/2016 && work of weekend 1/16/2016~1/17/2016

    part 组员                工作              工作耗时/h 明日计划 工作耗时/h    UI 冯晓云  组内对生词卡片又重新进行了讨论:准备最后的发布和整个开发的整理 ...

  2. 2016 daily

    2016.01.06 leetcode 切题数达到 200+,截止目前 137.虽然一年 63 题看似不多,但是 easy 的题目基本已经切完,质量 >> 数量(专注 leetcode,可 ...

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

  4. [linux]阿里云主机的免登陆安全SSH配置与思考

    公司服务器使用的第三方云端服务,即阿里云,而本地需要经常去登录到服务器做相应的配置工作,鉴于此,每次登录都要使用密码是比较烦躁的,本着极速思想,我们需要配置我们的免登陆. 一 理论概述 SSH介绍 S ...

  5. Python标准模块--Unicode

    1 模块简介 Python 3中最大的变化之一就是删除了Unicode类型.在Python 2中,有str类型和unicode类型,例如, Python 2.7.6 (default, Oct 26 ...

  6. 使用Expression实现数据的任意字段过滤(1)

    在项目常常要和数据表格打交道. 现在BS的通常做法都是前端用一个js的Grid控件, 然后通过ajax的方式从后台加载数据, 然后将数据和Grid绑定. 数据往往不是一页可以显示完的, 所以要加分页: ...

  7. Nginx 访问日志轮询切割

    Nginx 访问日志轮询切割脚本 #!/bin/sh Dateformat=`date +%Y%m%d` Basedir="/application/nginx" Nginxlog ...

  8. Python Logging模块的简单使用

    前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...

  9. Oracle备库TNS连接失败的分析

    今天在测试12c的temp_undo的时候,准备在备库上测试一下,突然发现备库使用TNS连接竟然失败. 抛出的错误如下: $ sqlplus sys/oracle@testdb as sysdba S ...

  10. SQL语句来查询今天、昨天、7天内、30天的数据,经典!

    ---恢复内容开始--- 今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0 昨天的所有数据:select * f ...

随机推荐

  1. 生成中文版JavaDoc

    RT. 在用IDEA生成中文版JavaDoc时,出现如下问题: java.lang.IllegalArgumentException at sun.net.www.ParseUtil.decode(P ...

  2. GDI+的常用类

    VisualStyleRenderer 提供用于绘制和获取有关 System.Windows.Forms.VisualStyles.VisualStyleElement 的信息的方法. VisualS ...

  3. C++实现CString和string的互相转换

    CString->std::string 例子: CString strMfc=“test“; std::string strStl; strStl=strMfc.GetBuffer(0); u ...

  4. 网络(一),libevent客户端部分

    网络模块() 一.服务端: 暂时就以libevent模块,共享内存等下 .GS打开,首先创建4个libevent子线程,当然为每个线程设置连接通知回调函数,这个是基于sockpair的,然后再创建一个 ...

  5. [百度空间] [转] 在 Visual C++ 中控制全局对象的初始化顺序

    from: http://blog.csdn.net/classfactory/archive/2004/08/07/68202.aspx 在 C++ 中,同一个翻译单位(.cpp文件)里的全局对象的 ...

  6. HTML5中表单验证的8种方法(转)

    在深人探讨表单验证之前,让我们先思考一下表单验证的真实含义.就其核心而言,表单验证是一套系统,它为终端用户检测无效的控件数据并标记这些错误.换言之,表单验证就是在表单提交服务器前对其进行一系列的检查并 ...

  7. explicit构造函数的作用

    explicit构造函数是用来防止隐式转换的.请看下面的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...

  8. ASP.NET MVC 3和Razor中的@helper 语法

    原文:http://kb.cnblogs.com/page/102191/ ASP.NET MVC 3支持一项名为"Razor"的新视图引擎选项(除了继续支持/加强现有的.aspx ...

  9. 利用 NGINX 最大化 Python 性能,第一部分:Web 服务和缓存

    [编者按]本文主要介绍 nginx 的主要功能以及如何通过 NGINX 优化 Python 应用性能.本文系国内 ITOM 管理平台 OneAPM 编译呈现. Python 的著名之处在于使用简单方便 ...

  10. Android屏幕适应详解(二)

    android应用自适应多分辨率的解决方法 1. 首先是建立多个layout文件夹(drawable也一样).  在res目录下建立多个layout文件夹,文件夹名称为layout-800x480等. ...