Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466
噗,b没写出来啊。a写完后过了40分钟了啊,罚时4次啊!果然太弱
总结:
a题看错题,没有考虑m>=n其实也是可行的,导致调了40min。。。b题不会。。。。。。(暴力是硬伤。。),c题一开始交了tle。。。。。。然后改了下才过。。rp好。
很多情况下2种决策取最优我们可以枚举其中一种决策的数目然后计算另一种决策的数目。。简称打暴力打到家
题意:要过n个站,每次可以选择过1个站花费a卢布,也可以选择过m个站花b卢布
方法一:枚举其中一种,另一种可直接算出。。。(噗,看了tourist的代码才发现。。。。。。。。。。。。。。。。。我是sb,论暴力的重要性)
方法二:完全背包,但是体积并不是n,,而是>=n。。。。。。。(看来我被固定思维了。。。不行。。。得治。。)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } int n, m, a, b, ans, f[2005]; int main() {
read(n); read(m); read(a); read(b);
CC(f, 0x3f); f[0]=0;
for1(i, 1, 2) {
int v, w;
if(i==1) v=1, w=a;
if(i==2) v=m, w=b;
for1(j, v, 2000) f[j]=min(f[j], f[j-v]+w);
}
ans=~0u>>1;
for1(i, n, 2000) ans=min(f[i], ans);
printf("%d", ans);
return 0;
}
题意:给你一个矩阵a×b,然后需要面积>=n*6,每次可以(任意)扩大a和b,问扩大满足>=n*6后最小的面积及其边长。
果然还是不会暴力。。。。。。看tourist的代码好像就是暴力?这种情况和a题的一样,2种决策。。扩大a和扩大b。。枚举其中一个即可。。
(还没写。。QAQ
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } long long ans=~0ull>>1, xx, yy, a, b, n; int main() {
cin >> n >> a >> b;
if(a*b>=n*6) {
printf("%I64d\n%I64d %I64d\n", a*b, a, b);
}
else {
n*=6; bool flag=0;
if(a>b) swap(a, b), flag=1;
for(long long i=1; i<=n; ++i) {
long long x=i, y=(n+x-1)/x;
if(x>y) break;
if(x<a) x=a;
if(y<b) y=b;
if(x*y<ans) {
ans=x*y, xx=x, yy=y;
}
}
if(flag) swap(xx, yy);
printf("%I64d\n%I64d %I64d\n", ans, xx, yy);
}
return 0;
}
题意:给你n个数,分成连续的3部分,使得3部分的和相等,问分的方案数。
因为是连续的,那么一段是1~k,第二段是k+1~j,第三段是j+1~n,那么我们发现,当且1~k的和为sum{a[i]}/3的时候才考虑第二段,第三段相同
于是很容易得出
for1(i, 1, n-2) {
if(sum[i]==sz)
for1(j, i+1, n-1)
if(sum[j]-sum[i]==sz)
++ans;
而这是n^2的,,一开始我没看题直接交。。然后tle了。。
我们发现,其实sum[i]是一定==sz的,所以在sum[j]-sum[i]==sz可以变成sum[j]==sz+sum[i]==sz*2
那么我们发现,只要维护对于每一个位置i,判断它的前缀和是否==sz×2,那么在更新的时候,答案可以直接加上i+1后边sum[j]==sz*2的数量。
即我们再维护一个前缀和表示sz*2的数量,那么位置i后的数量就为cnt[n-1]-cnt[i],这里n-1是因为还要分一段,即第三段。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
typedef long long ll;
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const ll getint() { ll r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }
const int N=5*1e5 + 100;
int n;
ll sum[N], cnt[N], ans, a[N];
int main() {
read(n);
for1(i, 1, n) read(a[i]), sum[i]=sum[i-1]+a[i];
if(sum[n]%3!=0) puts("0");
else {
ll sz=sum[n]/3;
for1(i, 1, n) if(sum[i]==(sz<<1)) cnt[i]=1;
for1(i, 1, n) cnt[i]+=cnt[i-1];
for1(i, 1, n-2) {
if(sum[i]==sz)
ans+=cnt[n-1]-cnt[i];
}
printf("%I64d", ans);
}
return 0;
}
Codeforces Round #266 (Div. 2)的更多相关文章
- Codeforces Round #266 (Div.2) B Wonder Room --枚举
题意:给出一个两边长为a,b的矩形,要求增加a和增加b使a*b>=6*n且a*b最小. 解法:设新的a,b为a1,b1,且设a<b,那么a<=a1<=ceil(sqrt(6*n ...
- Codeforces Round #266 (Div. 2) D
D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #266 (Div. 2)-C,D
C - Number of Ways 直接暴力从前往后寻找.假设找到1/3sum的位置,那么标记++.找到2/3的位置,总数加上标记数. #include<stdio.h> #includ ...
- Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...
- Codeforces Round #266 (Div. 2) C. Number of Ways
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- 算法笔记_023:拓扑排序(Java)
目录 1 问题描述 2 解决方案 2.1 基于减治法实现 2.2 基于深度优先查找实现 1 问题描述 给定一个有向图,求取此图的拓扑排序序列. 那么,何为拓扑排序? 定义:将有向图中的顶点以线性方式进 ...
- Python 对字符串切片
对字符串切片字符串 'xxx'和 Unicode字符串 u'xxx'也可以看成是一种list,每个元素就是一个字符.因此,字符串也可以用切片操作,只是操作结果仍是字符串:>>> 'A ...
- 【VBA】点击工作簿中的每个单元格,整行整列变色
需求描述 在点击单元格的时候,单元格所在行与列都变色显示 实现方案 打开Excle表格,按住ALT+F11 双击上图中的ThisWorkbook Private Sub Workbook_SheetS ...
- UISearchbar去除背景色的方法,适合iOS5/6/7/8.0beta
通常使用UISearchbar都须要去除其背景色来与自己的界面风格保持协调,可是UISearchbar的设计随着iOS版本号的升级不断地在发生着变化.以下我们通过分析UISearchbar在各个iOS ...
- 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...
- Linux命令-帮助命令:help
which cd 查找cd命令的位置 which umask 查找umask命令的位置 Shell就是命令解释器,就是当你敲了一个命令,谁来把这个命令传递给内核,内核运行结束后返回一个结果,是谁把这个 ...
- Linux命令-帮助命令:man
man ls 查看ls命令的帮助信息(输出结果和less命令一样,需要空格,回车,,上箭头,下箭头,PgUp,PgDn,q等方式浏览) 注意:由于这个文件信息量比较大,需要查找某一个字符,输入/,输入 ...
- nodejs http代理请求
一些免费到代理地址 http://www.xicidaili.com/nn https://proxy.l337.tech/txt http://www.66ip.cn/nm.html 以下代码可以测 ...
- 区别getElementByID,getElementsByName,getElementsByTagName
以人来举例说明,人有能标识身份的身份证,有姓名,有类别(大人.小孩.老人)等. 1. ID 是一个人的身份证号码,是唯一的.所以通过getElementById获取的是指定的一个人. 2. Name ...
- atitit.自己动手开发编译器and解释器(2) ------语法分析,语义分析,代码生成--attilax总结
atitit.自己动手开发编译器and解释器(2) ------语法分析,语义分析,代码生成--attilax总结 1. 建立AST 抽象语法树 Abstract Syntax Tree,AST) 1 ...