Superhero Transformation
1111 A
https://codeforces.com/problemset/problem/1111/A
题意:
求两个字符串对应的元音字母和其他字母是否均在同一位置上。
扫描字符串,但是要加上双重判断,既要判断A串也要判断B串。
AC代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int T;
double n;
typedef long long ll;
string a,b;
int main(){
cin >> a >> b;
if(a.length() != b.length()) {
cout << "NO" << endl;
}
else {
int lena = a.length();
//int lenb = b.length();
bool f = 1;
for(int i = 0; i < lena; i++) {
if((a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') ) {
a[i] = '1';
}
else {
a[i] = '2';
}
}
for(int i = 0; i < lena; i++) {
if((b[i] == 'a' || b[i] == 'e' || b[i] == 'i' || b[i] == 'o' || b[i] == 'u')) {
b[i] = '1';
}else {
b[i] = '2';
}
}
if(a == b) cout << "Yes" << endl;
else cout <<"No" << endl;
}
return 0;
}
1111B
Average Superhero Gang Power
https://codeforces.com/problemset/problem/1111/B
题意:
有N个超级英雄,你可以进行M次操作,对每个英雄最高不超过K次增加,要求其所有平均值最大化。
这是一道很开拓思维的题目。
题目并非可以直接删除值最低的几个数字从而增加平均值。
而是需要一边删除一边判断。
AC代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, k, m;
const int maxn = 1e5 + 5;
ll a[maxn];
ll sum = 0;
int main(){
cin >> n >> k >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i]; //SUM存放总和值
}
sort(a+1,a+n+1);
double ans = (double)(sum + min((k*n), m)) / (double)n; //ans是最初的平均值
if(n == 1) printf("%.20lf\n",ans);
else {
for (int i = 1; i <= min(n - 1, m); i++) {
sum -= a[i]; //删除最低的
//min((n - i)*k,(m-i))代表了当前可以加的最大值
double tmp = (double)(sum + min((n - i)*k,(m-i))) /(double) (n-i);
ans = max(ans,tmp);
}
printf("%.20lf\n",ans);
}
return 0;
}
Minimum Binary Number
976A
https://codeforces.com/problemset/problem/976/A
题意:
不论有多少1 最后都只剩一个1其他全是0
AC代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int T;
typedef long long ll;
string a;
int main(){
cin >> T;
cin >> a;
int sum1 = 0;
int sum0 = 0;
for(int i = 0; i < T; i++) {
if(a[i] == '1') sum1++;
else sum0++;
}
if(sum1) cout <<"1";
for(int i = 0; i < sum0;i++) cout<<"0";
return 0;
}
Lara Croft and the New Game
976B
https://codeforces.com/problemset/problem/976/B
题意:
找规律,这题规律不算很好找。
行的话 L = n - (k - n) / (m - 1)
列的话 由于奇数行和偶数行行走的方向并非是一致的,因此还需要判断。
取模中的(m-1)是因为仅有(m-1)个列(第一列已经特判),而非是随意选取的值。
AC代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, m, k;
int main(){
cin >> n >> m >> k;
if(k < n) cout << k+1 <<" 1" << endl;
else {
k -= n;
ll l = n - k/(m-1);
if(l&1) {
ll r = m - (k%(m-1));
cout <<l <<" " << r << endl;
}else {
ll r = k%(m-1)+2;
cout << l << " " << r << endl;
}
}
return 0;
}