2022 SMU-XCPC 集训队新生赛
# 游乐园
因为套票更加便宜,根据贪心应该尽可能的选择套票。
#include<bits/stdc++.h>
using namespace std;
int main(){
int x , y;
cin >> x >> y;
cout << 60 * x + 40 * y - 10 * min( x , y );
}
口算练习
认真读读题就好了
#include<bits/stdc++.h>
using namespace std;
int32_t main() {
int a , b;
cin >> a >> b;
cout << (int) floor( 1.0 * a / b ) << "\n";
return 0;
}
群管理员
循环判断就好,但是要注意数据范围
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
int32_t main() {
int n = read() , k = read() , cnt = 0;
for( int x ; n ; n -- )
x = read() , cnt += ( k == x );
cout << cnt << "\n";
return 0;
}
集卡
依旧是循环判断就好,但是注意空间限制不能使用数组
#include<bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
int32_t main() {
for( int t = read() , n , x , flag ; t ; t -- ){
n = read() , flag = 0;
for( ; n ; n -- ){
x = read();
if( x == 0 ) flag = 1;
}
cout << ( flag ? "yes\n" : "no\n" );
}
return 0;
}
排队
简单的分一下奇偶数就好了
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
int32_t main() {
vector<int> a , b;
for( int n = read() , x ; n ; n -- ){
x = read();
if( x & 1 ) a.push_back(x);
else b.push_back(x);
}
for( int it : a )
printf("%d " , it );
printf("\n");
for( int it : b )
printf("%d " , it );
printf("\n");
return 0;
}
smuxcpc
直接遍历一下字符串就好了
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int ans=0;
cin>>s;
for(int i=0;i<s.length();i++){
if(s[i]=='s'){
if(s[i+1]=='m'&&s[i+2]=='u'&&s[i+3]=='x'&&s[i+4]=='c'&&s[i+5]=='p'&&s[i+6]=='c')
ans++;
}
}
cout<<ans<<endl;
return 0;
}
可以直接用python 写
print(input().count("smuxcpc"))
也可用用新语法
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl (char)10
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int ans = 0, op = 0;
string s; cin >> s;
for (int tmp = s.find("smuxcpc", op), op = tmp + 1; tmp != s.npos; tmp = s.find("smuxcpc", op), op = tmp + 1) {
ans++;
}
cout << ans << endl;
return 0;
}
军训
这题其实算是本厂最困难的一道题了,我们要学会读题,使用题目给出的数据生成器生成序列和询问区间,注意对于最小值应该输出编号
#include<bits/stdc++.h>
using namespace std;
int data( int & seed , int n ){
seed = (seed % 123456 + seed % 10000007) % n + 1;
return seed;
}
int32_t main() {
int n , m ,seed;
cin >> n >> m >> seed;
vector<int> a(n+1);
for( int i = 1 ; i <= n ; i ++ )
a[i] = data( seed , n );
for( int i = 1 ,op , l , r ; i <= m ; i ++ ){
op = data( seed , n ) , l = data( seed , n ) , r = data( seed , n );
if( l > r ) swap( l , r );
if( op & 1 ){
int res = INT_MIN;
for( int i = l ; i <= r ; i ++ )
res = max( res , a[i] );
cout << res << "\n";
}else{
int res = INT_MAX , id = 0;
for( int i = l ; i <= r ; i ++ )
if( a[i] < res ) res = a[i] , id = i;
cout << id << "\n";
}
}
return 0;
}
omemi的心事
这道题应该才是最简单一题,注意题目并不是难度递增的哟
#include <iostream>
using namespace std;
int main(){
char c;
cin >> c;
cout << (int)c;
}