前言
我叫zps,准考证号JS-00810,来自苏州。今年我AK了CSP-J。总体感觉还是很水的,但是似乎没什么人AK。我表示不理解。总之,写个博客好了。
T1 数字游戏(number)
题面
给定一个保证长度为 8 8 8的01字符串,求这个字符串中有多少1。
题解
这还要解?签到题好吧…只要会打文件就能过。
时间复杂度 O ( 8 ) O(8) O(8)。你要认为是 O ( 1 ) O(1) O(1)也珂以。
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
namespace Flandre_Scarlet
{
#define N 100
#define MEM(x,a) memset(x,a,sizeof(x))
#define CL(x) MEM(x,0)
#define F(i,l,r) for(int i=l;i<=r;++i)
#define D(i,r,l) for(int i=r;i>=l;--i)
#define Fs(i,l,r,c) for(int i=l;i<=r;c)
#define Ds(i,r,l,c) for(int i=r;i>=l;c)
char s[N];int n;
void Input()
{
scanf("%s",s+1);n=strlen(s+1);
}
void Solve()
{
int ans=0;
F(i,1,n) if (s[i]=='1') ans++;
printf("%d\n",ans);
}
void Main()
{
bool OPEN_FILE=0; //考场上要改为1,需要开文件
if (OPEN_FILE)
{
#define filename "number"
freopen(filename ".in","r",stdin);
freopen(filename ".out","w",stdout);
}
Input();
Solve();
}
}
int main()
{
Flandre_Scarlet::Main();
return 0;
}
T2 公交换乘(transfer)
题面
你近期有 n < = 1 e 5 n<=1e5 n<=1e5个乘坐公共交通的记录,有些是地铁,有些是公交。每次都有三个值: p , t , k p,t,k p,t,k。 k = 0 k=0 k=0表示地铁, = 1 =1 =1表示公交。 p p p表示价格。 t t t表示时刻。每坐一次地铁都会在上车时得到一个坐公交车的优惠券。如果两个时刻 t b u s , t s u b w a y t_{bus},t_{subway} tbus,tsubway之间满足 t b u s − t s u b w a y < = 45 t_{bus}-t_{subway}<=45 tbus−tsubway<=45且 t b u s > t s u b w a y t_{bus}>t_{subway} tbus>tsubway,则可以使用一张优惠券,免费乘坐公交。
合理分配优惠券使得总花费最小。保证时间 t t t严格递增是顺序给出的。
题解
由于时间是严格递增的,时间差要 < = 45 <=45 <=45,所以每次至少会 + 1 +1 +1。所以,对于每个公交车,最多有 45 45 4