2018-05-26考试

T1为什么只有我推得那么奇怪…

%%%AK巨佬HYJ

结果

题面

T1

T2

T3

题解

T1

Method$1$

由题:

$ans$可以倒推

设当前$i=ans,\;a_1=x_i^2(i+1),\;b_1=ix_i$

$$\therefore a_1a+b_1b+c=-b_1-i$$

令$p=-b_1-i,\;q=a_0-b_0,\;r=b_0-c_0$

解得:$b=\frac{p-a_1q+r}{a_1+b_1+1}$

可得上一次答案为$ans_1=b-b_0$

倒推即可

但是会爆long long

Method$2$

由题:

设$a_1,\;b_1,\;x=ans_1$

$$\therefore a_1a_0+b_1(b_0+1)+c_1+i$$

$$=a_1a+b_1(b+1)+c+i-a_1x-b_1x-x$$

$$=-(a_1+b_1+1)x$$

令$y=a_1a_0+b_1(b_0+1)+c_1+i$

$$\therefore x=-\frac{y}{a_1+b_1+1}$$

T2, T3

太简单, 不讲

代码

T1

Method$2$
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
#include<bits/stdc++.h>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

inline int read()
{
int 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(50010), maxq(500010);
int a[maxq], b[maxq], s[maxn], n, cnt, ans[maxq];
long long c[maxq];

int main()
{
n=read(); cnt=1;
for(RG int i=1;i<=n;i++) s[i]=read();
while(scanf("%d%d%lld", &a[cnt], &b[cnt], &c[cnt])!=EOF) ++cnt;
--cnt; ans[cnt-1]=-a[cnt];
for(RG int i=cnt-1;i-1;i--)
{
long long a1=1ll*(ans[i]+1)*s[ans[i]]*s[ans[i]];
long long b1=1ll*ans[i]*s[ans[i]];
ans[i-1]=-(1ll*a1*a[i]+1ll*(b[i]+1)*b1+c[i]+ans[i])/(a1+b1+1);
}
for(RG int i=1;i<cnt;i++) printf("%d\n", ans[i]);
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
#include<bits/stdc++.h>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

inline int read()
{
int 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), mod(1e9+9);
int n, m, x, ans;
char s[3];
struct node { char a; int x; } p[maxn];
inline bool cmp(const node &a, const node &b) { return a.x<b.x; }

int main()
{
n=read(); m=read(); ans=1;
for(RG int i=1;i<=m;i++)
{
scanf("%s%d", s, &x);
p[i]=(node){s[0], x};
}
sort(p+1, p+m+1, cmp);
for(RG int i=2;i<=m;i++) if(p[i].a^p[i-1].a) ans=1ll*ans*(p[i].x-p[i-1].x)%mod;
printf("%d\n", ans);
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
#include<bits/stdc++.h>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

inline int read()
{
int 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(1010), maxm(10010);
struct edge { int next, to, dis; } e[maxm << 2];
int head[maxn], e_num, n, ML, DL, a, b, c, dis[maxn], cnt[maxn];
bool inque[maxn];
inline void add_edge(int from, int to, int dis)
{
e[++e_num]=(edge){head[from], to, dis};
head[from]=e_num;
}

queue<int> q;
inline int spfa()
{
inque[1]=cnt[1]=1; dis[1]=0;
q.push(1);
while(!q.empty())
{
int x=q.front(); q.pop();
if(cnt[x]>=n) return -1;
for(RG int i=head[x];i;i=e[i].next)
{
int to=e[i].to;
if(dis[x]+e[i].dis<dis[to])
{
dis[to]=dis[x]+e[i].dis;
if(!inque[to])
{
inque[to]=true; ++cnt[to];
if(cnt[to]>=n) return -1;
q.push(to);
}
}
}
inque[x]=false;
}
return dis[n]^dis[0]?dis[n]:-2;
}

int main()
{
clear(dis, 63); n=read(); ML=read(); DL=read();
for(RG int i=1;i<=ML;i++)
{
a=read(); b=read(); c=read();
add_edge(a, b, c);
}
for(RG int i=1;i<=DL;i++)
{
a=read(); b=read(); c=read();
add_edge(b, a, -c);
}
printf("%d\n", spfa());
return 0;
}
Your browser is out-of-date!

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

×