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连试试水的深浅..... ...
随机推荐
- Servlet实现文件上传,可多文件上传
一.Servlet实现文件上传,需要添加第三方提供的jar包 接着把这两个jar包放到 lib文件夹下: 二: 文件上传的表单提交方式必须是POST方式, 编码类型:enctype="mul ...
- Android 读取assets文件下的txt文件
android 读取assets文件下的txt文件,解决了读取txt文件的乱码问题: package com.example.com.scrollview; import java.io.Buffer ...
- Bootstrap 3 Menu Generator
Bootstrap 3 Menu Generator
- 串口通讯编程一日通3(COMMTIMEOUTS DCB整理)
上一篇看了Overlapped IO模型后,接下来看剩下两个重要结构: 2.COMMTIMEOUTS结构 超时设置 COMMTIMEOUTS:COMMTIMEOUTS主要用于串口超时参数设置.COM ...
- findlibrary returned null产生的联想,Android ndk开发打包时我们应该怎样注意平台的兼容(x86,arm,arm-v7a)
非常多朋友在开发Android JNI的的时候,会遇到findlibrary returned null的错误,由于某种原因,so没有打包到apk中.以下浅析下引起该错误的原因以及平台兼容性问题. A ...
- static 成员变量、static 成员函数、类/对象的大小
一.static 成员变量 对于特定类型的全体对象而言,有时候可能需要访问一个全局的变量.比如说统计某种类型对象已创建的数量. 如果我们用全局变量会破坏数据的封装,一般的用户代码都可以修改这个全局变量 ...
- pandas set_index和reset_index的用法
1.set_index DataFrame可以通过set_index方法,可以设置单索引和复合索引. DataFrame.set_index(keys, drop=True, append=False ...
- 温故而知新 通过chrome tool 查看是否产生闭包
function foo() { var a = 20 var b = 30 function bar() { debugger; return a + b } return bar; } var b ...
- Atitit.故障排除系列---php 程序网站数据库错误排除流程
Atitit.故障排除系列---php 程序网站数据库错误排除流程 Php页面报告的错误不能定位到myusql的db配置上...字说是db conn err Mysql 接入错误...大概查看哈能不能 ...
- android自定义控件(1)-自定义控件属性
那么还是针对我们之前写的自定义控件:开关按钮为例来说,在之前的基础上,我们来看看有哪些属性是可以自定义的:按钮的背景图片,按钮的滑块图片,和按钮的状态(是开还是关),实际上都应该是可以在xml文件中直 ...