A

直接模拟即可。

B

对数组中的值进行排序去重。发现若去重之后的数组中有大于 3 个数时无解,因为无法找到一个点到数轴上四个点的距离均相等。若去重之后的数组中只有三个值,则判断中间的值是否到两边的值相等,若不相等,同理无解,相等则解为距离。若只有两个不同的值,若中点是整数,则答案为中点到左端点的距离,否则为两点之间的距离。若只有一个不同的值,则答案直接为 0。

C

首先去掉整周的情况,先统计出有多少个完整的周。剩下为出发日所在周和结束日所在周的情况。将这两周拼成一周(十四天),枚举出发的时间,计算通过当前的食物可以到达的最远距离,取最大值后加入答案贡献即可。

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define cls(a,b) memset(a,b,sizeof(a))
#define debug(x) printf("x = %d\n",x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
//const int maxn=
const double eps=1e-6;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll sqr(ll x){return x*x;}
inline ll read(){
ll x=0,f=1;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
return f*x;
}
/*--------------------------------------------------------*/ const int s[]={0,1,2,0,2,1,0};
int a,b,c;
ll ans; void read_and_parse(){
a=read(),b=read(),c=read();
ans=min(a/3,min(b/2,c/2));
a-=ans*3,b-=ans*2,c-=ans*2;
ans*=7;
} void solve(){
int res=0;
for(int i=0;i<7;i++){
int ret=0,aa=a,bb=b,cc=c;
for(int j=i;j<i+7;j++){
if(s[j%7]==0){
if(aa)--aa,++ret;
else break;
}else if(s[j%7]==1){
if(bb)--bb,++ret;
else break;
}else{
if(cc)--cc,++ret;
else break;
}
}
res=max(res,ret);
}
printf("%lld\n",ans+res);
} int main(){
read_and_parse();
solve();
return 0;
}

D

贪心策略:在阳光下且油箱未满的时候,优先采用电平来供电,其他情况下优先采用太阳能供电。

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define cls(a,b) memset(a,b,sizeof(a))
#define debug(x) printf("x = %d\n",x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=2e5+10;
const double eps=1e-6;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll sqr(ll x){return x*x;}
inline ll read(){
ll x=0,f=1;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
return f*x;
}
/*--------------------------------------------------------*/ int n,b,a,now;
bool s[maxn]; void read_and_parse(){
n=read(),b=read(),a=read(),now=a;
for(int i=1;i<=n;i++)s[i]=read();
} void solve(){
for(int i=1;i<=n;i++){
if(s[i]==1){
if(b&&now<a){
--b,++now;
}else{
if(now)--now;
else return (void)printf("%d\n",i-1);
}
}else{
if(now)--now;
else if(b)--b;
else return (void)printf("%d\n",i-1);
}
}
printf("%d\n",n);
} int main(){
read_and_parse();
solve();
return 0;
}

E

采用双向链表进行模拟整个过程,因为每个人会且仅会被选择一次,因此时间复杂度为 \(O(n)\)。

By wzj_xhjbk, contest: Codeforces Round #552 (Div. 3), problem: (E) Two Teams, Accepted, #
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define cls(a,b) memset(a,b,sizeof(a))
#define debug(x) printf("x = %d\n",x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=2e5+10;
const double eps=1e-6;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll sqr(ll x){return x*x;}
inline ll read(){
ll x=0,f=1;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
return f*x;
}
/*--------------------------------------------------------*/ int n,k,a[maxn],d[maxn],tag[maxn],l[maxn],r[maxn]; bool cmp(int x,int y){return a[x]>a[y];} void read_and_parse(){
n=read(),k=read();
for(int i=1;i<=n;i++)a[i]=read(),d[i]=i,l[i]=i-1,r[i]=i+1;// 0 ~ n+1
sort(d+1,d+n+1,cmp);
} void solve(){
int clk=1;
for(int i=1;i<=n;i++){
if(tag[d[i]]!=0)continue;
tag[d[i]]=clk;
int pos=d[i],cnt=0,lb=0,rb=n+1;
while(l[pos]&&cnt<k)pos=l[pos],tag[pos]=clk,++cnt;
if(l[pos])lb=l[pos];
pos=d[i],cnt=0;
while(r[pos]<=n&&cnt<k)pos=r[pos],tag[pos]=clk,++cnt;
if(r[pos]<=n)rb=r[pos];
r[lb]=rb,l[rb]=lb;
clk=clk==1?2:1;
}
for(int i=1;i<=n;i++)printf("%d",tag[i]);
puts("");
} int main(){
read_and_parse();
solve();
return 0;
}

F

不考虑优惠策略,可以发现买 k 个物品的最小值即为所有物品中的前 k 小值之和,因此按照物品的价格进行排序。现在考虑优惠政策,设 \(dp[i]\) 表示买 i 个物品的最小值,则状态转移方程为 \(dp[i]=min\{dp[i],dp[i-a]+\sum\limits_{i=i-a+b+1}^{n}cost[i] \}\)。其中求和部分可以利用前缀和预处理,时间复杂度为 \(O(k*m)\)。

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define cls(a,b) memset(a,b,sizeof(a))
#define debug(x) printf("x = %d\n",x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=2e5+10;
const double eps=1e-6;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll sqr(ll x){return x*x;}
inline ll read(){
ll x=0,f=1;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
return f*x;
}
/*--------------------------------------------------------*/ int n,m,k,a[maxn];
ll dp[2010],sum[2010];
P off[maxn]; void read_and_parse(){
n=read(),m=read(),k=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=m;i++)off[i].fi=read(),off[i].se=read();
sort(a+1,a+n+1),sort(off+1,off+m+1);
} void solve(){
for(int i=1;i<=k;i++)sum[i]=sum[i-1]+a[i],dp[i]=sum[i];
for(int i=1;i<=k;i++){
for(int j=1;j<=m;j++){
if(off[j].fi>i)break;
dp[i]=min(dp[i],dp[i-off[j].fi]+sum[i]-sum[i-off[j].fi+off[j].se]);
}
}
printf("%lld\n",dp[k]);
} int main(){
read_and_parse();
solve();
return 0;
}

G

玄学复杂度。。考虑枚举 \(gcd\),每次找到序列中最小的两个数,计算最小公倍数与最优解进行比较即可。

【CF1154】题解的更多相关文章

  1. 【题解】CF1154

    A Description 有三个正整数 \(a,~b,~c\),现在给定 \(x_1~=~a + b,~x_2~=~a + c, x_3~=~b + c, ~x_4~=~a + b + c\),请求 ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. npm --save-dev 和--save 参数的区别

    npm中的--save与--save-dev参数的区别 --save一般规定把产品运行时(或生产环境)需要的npm包存入到package.json的dependencies中: --save-dev则 ...

  2. 你不知道的JavaScript——this词法

    https://www.cnblogs.com/hutaoer/p/3423782.htmlhttps://www.cnblogs.com/vicky-li/p/8669549.htmlhttps:/ ...

  3. oninput和onchange的区别

    菜鸟教程: oninput事件:HTML5标准事件 当用户向<input>中尝试输入时执行JavaScript: <input type="text" oninp ...

  4. CDH 6.0.1 集群搭建 「Process」

    这次搭建我使用的机器 os 是 Centos7.4 RH 系的下面以流的方式纪录搭建过程以及注意事项 Step1: 配置域名相关,因为只有三台机器组集群,所以直接使用了 hosts 的方法: 修改主机 ...

  5. Python实现百度贴吧自动顶贴机

    开发这款小工具,我们需要做一些准备: url.txt:多个需要顶起的帖子地址. reply:多条随机回复的内容. selenium:浏览器自动化测试框架 首先,我们先使用pip完成selenium的安 ...

  6. Wpf ViewModel中 ObservableCollection不支持从调度程序线程以外的线程对其 SourceCollection 进行的更改

    Wpf中ViewModel类里面经常会需要用到ObservableCollection来管理列表数据,在做异步通信的时候也会碰到“不支持从调度程序线程以外的线程对其 SourceCollection ...

  7. Nginx 针对建立TCP连接优化

    L:124 sysctl -a | grep file-max //通过命令查看系统最大句柄数 [root@3 ~]# sysctl -a | grep file-max fs.file-max = ...

  8. 使用aapt查看当前apk的属性

    android:versioncode——整数值,代表应用程序代码的相对版本,也就是版本更新过多少次. android:versionname——字符串值,代表应用程序的版本信息,需要显示给用户. e ...

  9. IntelliJ IDEA default settings 全局默认设置

    可以通过以下两个位置设置IDEA的全局默认设置: 以后诸如默认的maven配置就不需要每次都重复配置了?

  10. 异步、+回调机制、线程queue、线程Event、协程、单线程实现遇到IO切换

    # from concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor # import requests # import o ...