Codeforces Round #521 Div. 3 玩耍记
A:签到。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int T;
int main()
{
T=read();
while (T--)
{
int a=read(),b=read(),k=read();
if (k&) cout<<1ll*(a-b)*(k>>)+a<<endl;
else cout<<1ll*(a-b)*(k>>)<<endl;
}
return ;
}
B:将能提供2贡献的位置先取反再扫一遍即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,a[N],ans=;
int main()
{
n=read();
for (int i=;i<=n;i++) a[i]=read();
for (int i=;i<=n-;i++) if (a[i]==&&a[i-]==&&a[i+]==&&a[i-]==&&a[i+]==) ans++,a[i]=;
for (int i=;i<n;i++) if (a[i]==&&a[i-]==&&a[i+]==) ans++,a[i+]=;
cout<<ans;
return ;
}
C:桶记录出现数字次数,枚举删掉的数字即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
#define M 1000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,a[N],b[N],tot[M],cnt;
ll sum;
int main()
{
n=read();
for (int i=;i<=n;i++) sum+=a[i]=read(),tot[a[i]]++;
for (int i=;i<=n;i++)
{
ll x=sum-a[i];
if (x<=&&x%==&&tot[x/]>(a[i]==x/)) b[++cnt]=i;
}
cout<<cnt<<endl;
for (int i=;i<=cnt;i++) printf("%d ",b[i]);
return ;
}
D:二分答案贪心选取即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,m,cnt[N],id[N],ans[N];
struct data
{
int x,y;
bool operator <(const data&a) const
{
return y>a.y;
}
}a[N],b[N];
bool check(int k)
{
for (int i=;i<=;i++) b[i]=a[i];
int s=;
for (int i=;i<=;i++)
while (b[i].y>=k&&s<m) id[++s]=b[i].x,b[i].y-=k;
return s>=m;
}
int main()
{
n=read(),m=read();
for (int i=;i<=n;i++) cnt[read()]++;
for (int i=;i<=;i++) a[i].x=i,a[i].y=cnt[i];
sort(a+,a+);
int l=,r=n/m;
while (l<=r)
{
int mid=l+r>>;
if (check(mid)) {for (int i=;i<=m;i++) ans[i]=id[i];l=mid+;}
else r=mid-;
}
for (int i=;i<=m;i++) printf("%d ",ans[i]);
return ;
}
E:枚举序列长度(显然是log级别的),二分首项大小,贪心选取即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,a[N],b[N],cnt[N],tot;
bool check(int k,int s)
{
int t=;
for (int i=;i<=n;i++)
{
if (a[i]>=k) t++,k<<=;
if (t==s) return ;
}
return ;
}
int main()
{
n=read();
for (int i=;i<=n;i++) b[i]=a[i]=read();
sort(b+,b+n+);
int t=unique(b+,b+n+)-b-;
for (int i=;i<=n;i++) a[i]=lower_bound(b+,b+t+,a[i])-b;
for (int i=;i<=n;i++) cnt[a[i]]++;
sort(cnt+,cnt+t+);
for (int i=;i<=t;i++) a[i]=cnt[i];
int tmp=n;
n=t;
for (int i=;i<=;i++)
{
int l=,r=tmp,ans=;
while (l<=r)
{
int mid=l+r>>;
if (check(mid,i)) ans=mid,l=mid+;
else r=mid-;
}
tot=max(tot,ans*((<<i)-));
}
cout<<tot;
return ;
}
F1:f[i][j]表示前i个数选取了j个且第i个被选的最大价值,转移枚举上次选哪个即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 5010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,m,k,a[N];
ll f[N][N];
int main()
{
n=read(),k=read(),m=read();
for (int i=;i<=n;i++) a[i]=read();
memset(f,,sizeof(f));
f[][]=;
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
for (int x=i-;x>=max(,i-k);x--)
f[i][j]=max(f[i][j],f[x][j-]+a[i]);
}
}
for (int i=n-;i>=max(,n-k+);i--) f[n][m]=max(f[n][m],f[i][m]);
if (f[n][m]<) cout<<-;
else cout<<f[n][m];
return ;
}
F2:在F1基础上单调队列优化即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 5010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,m,k,a[N],q[N],head,tail;
ll f[N][N];
int main()
{
n=read(),k=read(),m=read();
for (int i=;i<=n;i++) a[i]=read();
memset(f,,sizeof(f));
f[][]=;
for (int j=;j<=m;j++)
{
head=,tail=;q[]=;
for (int i=;i<=n;i++)
{
while (head<tail&&q[head]<i-k) head++;
f[i][j]=f[q[head]][j-]+a[i];
while (head<=tail&&f[q[tail]][j-]<=f[i][j-]) tail--;
q[++tail]=i;
}
}
for (int i=n-;i>=max(,n-k+);i--) f[n][m]=max(f[n][m],f[i][m]);
if (f[n][m]<) cout<<-;
else cout<<f[n][m];
return ;
}
小号打的。result:rank 3 rating +311
Codeforces Round #521 Div. 3 玩耍记的更多相关文章
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Codeforces Round #394 (Div. 2) 颓废记
昨天晚上(今天凌晨),又忍不住去打CF.(本蒟弱到只能打Div.2)... 我觉得我可以用一个词概括我这次的CF: 呵呵 刚一开赛,我就codeforces访问失败.. 后来好不容易能上了,两三分钟才 ...
- Codeforces Round#500 Div.2 翻车记
A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】
任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...
- CodeForces Round #521 (Div.3) E. Thematic Contests
http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...
- CodeForces Round #521 (Div.3) D. Cutting Out
http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...
- Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...
- Codeforces Round #402 (Div. 2) 阵亡记
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...
- CodeForces Round #521 (Div.3) B. Disturbed People
http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...
随机推荐
- 广州Uber优步司机奖励政策(12月14日到12月20日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- CF 643 E. Bear and Destroying Subtrees
E. Bear and Destroying Subtrees http://codeforces.com/problemset/problem/643/E 题意: Q个操作. 加点,在原来的树上加一 ...
- STM32的System memory
Main Flash memory 是STM32内置的Flash,一般我们使用JTAG或者SWD模式下载程序时,就是下载到这个里面,重启后也直接从这启动程序. System memory 从系统存储器 ...
- 可靠UDP,KCP协议快在哪?
WeTest 导读 云真机已经支持手机端的画面投影.云真机实时操作,对延迟的要求比远程视频对话的要求更高(100ms以内).在无线网络下,如何更实时.更可靠的传输视频流就成了一个挑战.通过websoc ...
- VS中添加新项 数据选项卡下没有ADO.NET实体数据模型解决方案
第一种:C:\ProgramData下面搜索EFTools找到你vs对应版本的EFTools.msi 先remove 然后再Install 重启电脑再看 第二种:如果意外地删除了 Visual Stu ...
- Java开发工程师(Web方向) - 04.Spring框架 - 第5章.Web框架
第5章--Web框架 Web框架概述 Web框架单元测验 本次得分为:13.50/15.00, 本次测试的提交时间为:2017-09-25 1单选(2分) 关于Spring MVC中Dispatche ...
- mybatis interceptor 处理查询参数及查询结果
拦截器:拦截update,query方法,处理查询参数及返回结果. /** * Created by windwant on 2017/1/12. */ @Intercepts({ @Signatur ...
- [SHELL]shell中的数学运算
一,expr 太麻烦,看的脑壳疼 二,使用方括号 !!!! bash shell用这种方法只支持整数运算,z shell倒是支持浮点型运算 var_1= var_2= var_3= my_var_1 ...
- [Clr via C#读书笔记]Cp7常量和字段
Cp7常量和字段 常量 常量在编译的时候必须确定,只能一编译器认定的基元类型.被视为静态,不需要static:直接嵌入IL中: 区别ReadOnly 只能在构造的时候初始化,内联初始化. 字段 数据成 ...
- Jedis 与 MySQL的连接线程安全问题
Jedis的连接是非线程安全的 下面是set命令的执行过程,简单分为两个过程,客户端向服务端发送数据,服务端向客户端返回数据,从下面的代码来看:从建立连接到执行命令是没有进行任何并发同步的控制 pub ...