CSDN第十五期周赛

第一次在csdn周赛中取得满分的成绩,先来说一些做题体验吧。

也可能是第一次使用类似的oj,不太适应他的评测机制,总感觉自测比较麻烦。不过评测机倒是挺快的。

这次的题感觉比以往几期稍微简单一点。

第一题判重排序就可以了。

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std ;
const int N = 1010 ;
int a[N * 2] , cnt ;
int main() {
int n;
int m;
unordered_set<int> s ;
cin >> n >> m ;
for(int i = 0 ; i < n + m ; i ++)
{
int x ;
scanf("%d",&x) ;
if(!s.count(x)) {
s.insert(x) ;
a[cnt ++] = x ;
}
}
sort(a , a + cnt) ;
for(int i = 0 ; i < cnt ; i ++)
if(i == cnt - 1) cout << a[i] ;
else cout << a[i] << " -> " ;
return 0;
}

第二题只需记录最大的数字,最后输出最大数+1即可。

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std ;
int n , maxv = 0 ;
int main() {
cin >> n ;
for(int i = 0 ; i < n ; i ++)
{
int x ;
scanf("%d",&x) ;
maxv = max(maxv , x) ;
}
cout << maxv + 1 << endl ;
return 0;
}

第三题有点考察思维了,既然说不能成环那我们为了保证建立最多的边,只要使两方边尽可能相等就可以了,(n/2) * (n - n/2),这就是答案了。

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
using namespace std ;
int main() {
int n;
cin >> n ;
if(n == 1) cout << "0" << endl ;
else
{
int x = n / 2 ;
int y = n - x ;
cout << x * y << endl ;
}
return 0;
}

第四题是之前给新生培训的一道原题,dp+贪心的解法就可以做出来。

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std ;
const int N = 10010 ;
int n , k , p , co , m ;

int l[N] , s[N] , c[N] ;
int main() {
cin >> n >> k >> p ;
int last = -1 , res = 0 ;
for(int i = 0 ; i < n ; i ++)
{
scanf("%d%d",&co,&m) ;
if(m <= p) last = i ;
if(last >= l[co]) s[co] = c[co] ;
res += s[co] ;
l[co] = i ;
c[co] ++ ;
}
cout << res << endl ;
return 0;
}

总的来说这次体验还是蛮不错的,也希望自己能取得更好的成绩。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安特尼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值