2018-02-04考试

题目:

题目在这里

题解在这里

代码:

T1 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

template<typename T = int>
inline T read()
{
T data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}

const int maxn(100010);
int n, k;
long long a[maxn], _max, s[maxn];

inline bool check(long long mid)
{
RG int l=1, tmpk=1;
for(RG int i=2;i<=n;i++)
{
if(s[i-1]-s[l-1]<=mid && s[i]-s[l-1]>mid)
{
l=i; tmpk++;
if(tmpk>k) return false;
}
}
return true;
}

int main()
{
file(seqa);
n=read(); k=read();
for(RG int i=1;i<=n;i++) s[i]=s[i-1]+(a[i]=read<long long>()), _max=max(_max, a[i]);
if(k==n) return printf("%lld\n", _max)&0;
if(k==1) return printf("%lld\n", s[n])&0;
long long l=_max, r=s[n];
while(l<r)
{
long long mid=(l+r)>>1;
bool ans=check(mid);
if(ans) r=mid;
else l=mid+1;
}
printf("%lld\n", r);
return 0;
}

T2 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

template<typename T = int>
inline T read()
{
T data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}

const int maxn(110);
int f[maxn][maxn], d1[maxn], d2[maxn], n, m;

inline bool check(int mid)
{
clear(f, -127/3);
f[0][0]=0;
for(RG int i=1;i<=n;i++)
for(RG int j=0;j<=m;j++)
for(RG int k=0;k<=j;k++)
if(mid>=d1[i]*k) f[i][j]=max(f[i][j], f[i-1][j-k]+(mid-d1[i]*k)/d2[i]);
return f[n][m]>=m;
}

int main()
{
n=read(); m=read();
for(RG int i=1;i<=n;i++) d1[i]=read(), d2[i]=read();
int l=1, r=1e6;
while(l<r)
{
int mid=(l+r)>>1;
bool ans=check(mid);
if(ans) r=mid;
else l=mid+1;
}
printf("%d\n", r);
return 0;
}

T3 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
namespace std { template<> inline void swap(int &x, int &y) { y^=x^=y^=x; } }
using namespace std;

template<typename T = long long>
inline T read()
{
T data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}

struct node { long long a, b, c, s1, s2; } p, q, rtp, rtq;
inline node turn(node &&x)
{
if(x.a>x.b) swap(x.a, x.b);
if(x.a>x.c) swap(x.a, x.c);
if(x.b>x.c) swap(x.c, x.b);
x.s1=x.b-x.a; x.s2=x.c-x.b;
return x;
}
inline pair<node, int> get_root(const node &x)
{
int depth=0;
int a=x.a, b=x.b, c=x.c, s1=x.s1, s2=x.s2;
while(s1!=s2)
{
if(s1<s2)
{
depth+=s2/s1; s2%=s1;
if(s2==0) s2=s1, depth--;
b=c-s2; a=b-s1;
}
else
{
depth+=s1/s2; s1%=s2;
if(s1==0) s1=s2, depth--;
b=a+s1; c=b+s2;
}
}
return {{a, b, c, s1, s2}, depth};
}
inline node jump(const node &x, int depth)
{
int a=x.a, b=x.b, c=x.c, s1=x.s1, s2=x.s2, dep=0;
while(s1!=s2)
{
if(s1<s2)
{
dep+=s2/s1;
if(dep>depth)
{
int tmp=depth-dep+s2/s1;
s2-=s1*tmp; b=c-s2; a=b-s1;
return {a, b, c, s1, s2};
}
else
{
s2%=s1;
if(s2==0) s2=s1, dep--;
b=c-s2; a=b-s1;
}
}
else
{
dep+=s1/s2;
if(dep>depth)
{
int tmp=depth-dep+s1/s2;
s1-=s2*tmp; b=a+s1; c=b+s2;
return {a, b, c, s1, s2};
}
else
{
s1%=s2;
if(s1==0) s1=s2, dep--;
b=a+s1; c=b+s2;
}
}
}
return {a, b, c, s1, s2};
}
bool operator == (const node &a, const node &b) { return a.a==b.a&&a.b==b.b&&a.c==b.c; }
int dp, dq;
int main()
{
p=turn({read(), read(), read(), 0, 0});
q=turn({read(), read(), read(), 0, 0});
auto t=get_root(p); rtp=t.first; dp=t.second;
t=get_root(q); rtq=t.first; dq=t.second;
if(!(rtp==rtq)) { puts("NO"); return 0; }
int ans=abs(dp-dq);
if(dp>dq) p=jump(p, dp-dq), dp=dq;
else q=jump(q, dq-dp), dq=dp;
int l=0, r=dp;
while(l<r)
{
int mid=(l+r)>>1;
node x=jump(p, mid), y=jump(q, mid);
if(x==y) r=mid;
else l=mid+1;
}
printf("YES\n%d\n", ans+(r<<1));
return 0;
}

总结 :

这一次,骗分达到了极限,自认为比较满意了。(逃)

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×