第二篇题解:
B. usaco2017feb_bronze Why Didthe Cow Cross the Road1
在这个例子中,犬3过马路两次特首先出现在第1侧,然后出现在第0边,然后再出现在第1边。犬4过马路一次。犬2和6似乎没有过马路。
数据规模与约定
翻译来自2020届: @102黄加瑜 @102慕昊天 @102叶景楠 @周靖涵
时间限制:1s1s
空间限制:256MB
这题我也没解,我一开始就没有看懂题目,然后悲剧了……不过还好,对了样例。
思路:这题有很多解法,我也不知道很多(香菇蓝瘦),现在介绍一位大佬的解法。
代码如下:
#include<bits/stdc++.h>
usingnamespace
std
;
intmain()
{
int
n
,x
,y
,s
=0;
cin
>>n
;
int
a
[11];
for(int
i
=1;i
<=10;i
++)
a
[i
]=2;
for(int
i
=1;i
<=n
;i
++)
{
cin
>>x
>>y
;
if(
a
[x
]!=y
&&a
[x
]!=2)
s
++;
a
[x
]=y
;
}
cout
<<s
;
return
0;
}
具体的没看太懂……(呜呜呜),像我们这种蒟蒻,只能膜拜。
大概就是在两边马路不在一边,就累加(我怎么没想到呢,被自己蠢哭了)。
操作:输入;
赋初值(不能是0或1);
循环并判断:是否不等于初值并不等于上次输入,成立则累加;
输出。
完~~~~~~;
第二题:
想哭~~,为什么会有银组题……
这题想都没想去做,混了个样例;
还是大佬代码:
#include<bits/stdc++.h>
usingnamespace
std
;
struct niu{
int
b
,c
;
}a
[100010];
int
x
,y
,m
,n
;
int
mx
;
intcmp(niu
x
,niuy
){
return
x
.c
<y
.c
;
}
intwork(){
x
=1;y
=n
;mx
=0;
while
(
x
<=y
){
int
sum
=a
[x
].c
+a
[y
].c
;
if
(
sum
>mx
)mx
=sum
;
if(
a
[x
].b
>a
[y
].b
){
a
[x
].b
-=a
[y
].b
;
y
--;
}
if(
a
[x
].b
==a
[y
].b
){
x
++;y
--;
}
if(
a
[x
].b
<a
[y
].b
){
a
[y
].b
-=a
[x
].b
;
x
++;
}
}
return
mx
;
}
intmain(){
scanf("%d",&
n
);
for
(int
i
=1;i
<=n
;i
++)
scanf("%d%d",&
a
[i
].b
,&a
[i
].c
);
sort(
a
+1,a
+n
+1,cmp
);
work();
printf("%d",
mx
);
return
0;
}
这次是真大佬:我表示我看不懂,更纪念品分组差不多(该死的背包、动态规划),具体自行理解吧(没办法,我看不懂)…………
完~~~~~;