qlu_acm个人赛第四场

A. Prefixes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
const int mod=1e9+7;
const int inf=1e9+7;
 
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//上面那句话就是来增加c++的cin和cout的输入输出速度的
(关闭cin和cout的缓存)	
	int n;
    cin>>n;
    string str;
    cin>>str;
    
    int cnt_a=0,cnt_b=0;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='a')
            cnt_a++;
        else if(str[i]=='b')
            cnt_b++;
        if(i&1)
        {//这地方可以这么写,因为当i为奇数时(因为i从0开始),i&1为真,就实现了没比较两个数就执行一次该if判断
            if(cnt_a!=cnt_b)
            {
                ans++;
                if(cnt_a==2)
                    str[i]='b';
                else if(cnt_b==2)
                    str[i]='a';    
            }
            cnt_a=0;    //一定要记得让cnt_a和cnt_b都等于0,进行下一轮比较
            cnt_b=0;
        }
    }
    
    cout<<ans<<endl;
    cout<<str<<endl;
    return 0;
}

B. Shooting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000+10;
typedef long long ll;
typedef struct
{
  int num;
  int id;
}st;
st sum[maxn];
bool cmp(st &a,st &b)
{
  return a.num>b.num;
  //从大到小来排列
}

int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>sum[i].num;
    sum[i].id=i;
  }
  sort(sum+1,sum+n+1,cmp);
  ll ans=0;
  for(int i=1;i<=n;i++)
   ans+=(i-1)*sum[i].num+1;
   //第一位乘的是0,第二次乘的是1,....
  cout<<ans<<endl;
  for(int i=1;i<=n;i++)
   cout<<sum[i].id<<" ";

  return 0;
}

Input
6
5 4 5 4 4 5
Output
69
6 1 3 5 2 4 
这一组数中下标从1开始,那么下标为1就对应这第一个5

D. Swords
思路:用最大数减去所给的值,然后对前n-1个值求一个gcd,然后除掉gcd求和就是答案。
这一题中说了最初的剑是一样的,所以最大的那个就是起初所有各种剑的数目。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
const int mod=1e9+7;
const int inf=1e9+7;
const int maxn=2e5+10;
ll int gcd(ll int a,ll int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int num[maxn];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int maxx=-1;
    for(int i=0;i<n;i++)
        cin>>num[i];
    sort(num,num+n);
    maxx=num[n-1];
    int now;
    for(int i=0;i<n-1;i++)
    {
        if(i==0)
            now=maxx-num[i];
        else
            now=gcd(now,maxx-num[i]);
    }
    ll int ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans+=(maxx-num[i])/now;
    }
    cout<<ans<<" "<<now<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值