A. Partition
题意:把n个数分为{B},{C},然后求B-C的最大值。
思路:就是求所有数字的绝对值的和。
#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
int main ()
{
//yyy_3y
//freopen("1.in","r",stdin);
int n; scanf("%d",&n);
LL sum=0;
for(int i=1;i<=n;i++){
int x; scanf("%d",&x);
if(x<0) sum= sum-x;
else sum+=x;
}
printf("%lld\n",sum);
return 0;
}
B. Weird Subtraction Process
题意:
如果a = 0或b = 0,则结束该过程。否则,请转到步骤2 ;
如果 a≥2· b,则 a= a - 2· b,并重复步骤1。否则,请转到步骤3 ;
如果b ≥2· a,b=b - 2·a,并重复步骤1。否则,结束该过程。
思路:模拟。
#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
int main ()
{
//yyy_3y
//freopen("1.in","r",stdin);
LL a,b; scanf("%lld%lld",&a,&b);
while(true){
if(a==0 || b==0) break;
if(a>=2*b){
a%=(2*b);
continue;
}
else {
if(b>=2*a) b%=(2*a);
else break;
}
}
printf("%lld %lld\n",a,b);
return 0;
}
C. String Transformation
题意:字符串转换。
在一次移动中,您可以将字符串的任何字符以字母顺序替换为下一个字符(a将被替换为b,s将替换为t等)。您不能用任何其他字母替换字母z。
问你能否把给出的串变成”abcdefghijklmnopqrstuvwxyz“
思路:枚举替换。
#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
string str="abcdefghijklmnopqrstuvwxyz";
string sc;
int main ()
{
//yyy_3y
//freopen("1.in","r",stdin);
cin >> sc;
int cnt=0;
for(int i=0;i<sc.size();i++){
if(sc[i]<=str[cnt]){
sc[i]=str[cnt];
cnt++;
}
if(cnt==26) break;
}
if(cnt==26) cout<<sc<<endl;
else cout<<"-1"<<endl;
}