2019省赛训练-N+7

http://acm.sdibt.edu.cn/vjudge/contest/view.action?cid=2225#overview

C - Apple Shops

 

Sample Input

Input
2
2 3
5 3
Output
2
12

题意:给出n,m,保证n,m互质,要求计算F(n,m)=gcd(5n+7n,5m+7m),数据量超大,找规律做。

思路:按照暴力的思路写出,运行程序,发现当n,m全为奇数的时候输出12,其他全为2.

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e3+10;
const int mod=1e9+7;
//int a[M],b[M][M];
//vector<int>v[M][M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,m,t;
    cin >>t;
    while(t--){
        cin >> n >> m;
        if(n%2==1&&m%2==1)
            cout << "12" <<endl;
        else
            cout << "2" <<endl;

    }
    return 0;
}

E - New Max

Input
3
4 2
abcd
1234
ac
4 4
abcd
1234
abec
5 3
abcba
24513
acb
Output
4
-1
8

题意:给出n,m,n代表有两个长度为n的字符串,第二个为第一个的花费,然后给出一个长度为m的字符串,问他们的最小花费’,直接记住每个字符的最小花费相加就好。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e3+10;
const int mod=1e9+7;
string s,t="10000110";

int m[M];
int main()
{
    int tt,n,nn;
    string s,c,t;
    cin >> tt;
    while(tt--)
    {
        int ans = 0;
        int flag = 0;
        mem(m,MAX);
        cin >> n >> nn;
        cin >> s;
        cin >> c;
        cin >> t;
        //cout <<s << ' ' << c << ' ' << t << endl;
        for(int i=0; i<n; i++){
            int x = c[i] - '0';
            if(x < m[s[i]-'a'])
                m[s[i]-'a'] = x;
        }

        for(int i=0; i<nn; i++){
            if(m[t[i]-'a'] == MAX){
                flag = 1;
                break;
            }
            else
                ans += m[t[i]-'a'];
        }
        if(flag)
            cout << "-1" << endl;
        else
            cout << ans <<endl;
    }
}

F - Who has a better strategy ?

Input
2
weFoundYou
isTheCamelCaseTheBestWayToNameAVariable
Output
YES
NO

题意:给出一个字符串,问能否分割不能超过7个单词吗,要求除第一个单词以外,其他分割好的单词首字母为大写,其他为小写,可以没有小写。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e4+10;
const int mod=1e9+7;
int f[M],a[M];
int xx,yy;
int g[M],b[M];
vector<int>v[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,x1,x2,y1,y2;
    cin >> n;
    while(n--){
        string s;
        int sum=1,flag=0;
        cin >>s;
        //cout << s[0] << "*";
        for(int i=0;i<s.size();i++){
            if(s[i]>='A'&&s[i]<='Z'){
                sum++;
            }
            if(sum>7){
                flag=1;
                break;
            }
        }
        if(flag)
            cout << "NO" <<endl;
        else
            cout << "YES" <<endl;
    }
    return 0;
}

I - Abu Tahun Mod problem

Input
3
3 1
4 6 2
4 2
-1 0 2 1
5 2
1 7 -4 2 -3
Output
8
4
17

题意:给出n,k,要求进行k次相反数操作,问n个数的和最大为多少。

思路:先判断负数跟k的关系,如果k大的话,可以先将负数变为整数,剩下的次数只变化现在最小的数就可以了。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e4+10;
const int mod=1e9+7;
int a[M],b[M];
vector<int>v[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int t;
    cin >> t;
    while(t--){
        int n,k,bb,z=0,f=0,sum1=0,sum2=0;
        int ans=0;
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++){
            scanf("%d",&bb);
            if(bb>=0){
                a[z++]=bb;

            }
            else {
                b[f++]=bb;
            }
        }
        sort(b,b+f);
        for(int i=0;i<f;i++){
            k--;
            if(k>=0){
                b[i]=-b[i];
            }
            a[z++]=b[i];

        }
        sort(a,a+z);
        if(k<0)
            k=0;
        if(k%2==0){
            for(int i=0;i<z;i++)
                ans+=a[i];
        }
        else{
            for(int i=1;i<z;i++)
                ans+=a[i];
            ans-=a[0];
        }
        cout <<ans <<endl;
    }
    return 0;
}

J - Negative effect

Input
2
2 3
1 2 3
4 1 2
3 3
5 7 9
3 2 9
5 3 2
Output
2
3

题意:给出n行m列的数字,同一行可以交换位置,问上下相同最多有多少个。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e3+10;
const int mod=1e9+7;
int b[M][M];
map<ll,ll>a;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m,bb,ans=0;
        scanf("%d%d",&n,&m);
        mem(b,0);
        a.clear();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%d",&b[i][j]);
                if(i==1){
                    a[b[i][j]]++;
                }
                else{
                    if(a[b[i][j]]>0){
                        ans++;
                        a[b[i][j]]--;
                    }
                }
                if(j==m){
                    a.clear();
                    for(int k=1;k<=m;k++)
                        a[b[i][k]]++;
                }
            }
        }

        printf("%d\n",ans);
    }
    return 0;
}

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值