第一次在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;
}
总的来说这次体验还是蛮不错的,也希望自己能取得更好的成绩。