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. C# Note31: 如何使用Visual Studio做单元测试

    待更! 使用Visual Studio 2013进行单元测试--初级篇 带你玩转Visual Studio——单元测试(C++例)

  2. mysql 分库分表备份脚本

    #!/bin/bash USER=root #用户 PASSWORD=123456 #密码 MYSQL_PATH=127.0.0.1 #地址 MYSQL_BIN=/bin/mysql MYSQL_DU ...

  3. jenkins和jdk版本问题

    问题:公司业务是用的jdk1.7的,但最新版的jenkins (jenkins-2.138.2-1.1.noarch.rpm)却只支持jdk1.8 分析: 1.公司业务用的jdk1.7不能换,不然影响 ...

  4. GitHub & OAuth 2.0 & JWT

    GitHub & OAuth 2.0 & JWT https://www.rfcreader.com/#rfc6749 GitHub & OAuth https://www.b ...

  5. Lodop打印控件打印机可打区域的影响 设置纸张边缘为基点

    由于打印机千差万别,打印开发也要注意针对客户各种打印机进行处理,Lodop提供了打印维护(PRINT_SETUP)可针对每个客户端进行微调,保存结果保存在客户端本地,对其他访问网站的客户没有影响. 由 ...

  6. 训练赛-Move Between Numbers

    题意:给你n个数,每个数有20个数字,每两个数字之间如果相等的数字数量为17个(一定是17),就能从一个数字到达另一个数字,给你两个数字编号,求从第一个数字编号到第二个数字编号之间最少需要走几次: 解 ...

  7. CentOS安装、配置Nginx反向代理

    添加Nginx存储库 sudo yum install epel-release 安装Nginx sudo yum install nginx 启动Nginx sudo systemctl start ...

  8. 洛谷P1462通往奥格瑞玛的道路题解

    [题目]: https://www.luogu.org/problemnew/show/P1462 题意 题目是给定了一张双向边,有边权的图,然后让我们求出一个最小值,满足一条路径上的最大的费用小于这 ...

  9. ysg 一道简单的数论题

    先声明一点,这个题从一套模拟题中选取出来,所以可能会冒犯到原出题人.请谅解 题干: ysg,yxy,azw 三人正在刷题. 他们每做一题的时间都是一个有理数. 如果在某一时刻,三人同时做完一道 题,那 ...

  10. centos安装php7.2环境

    centos安装php7.2环境 安装apache服务 yum -y install httpd 首先获取rpm: rpm -Uvh https://dl.fedoraproject.org/pub/ ...