清明比赛 水题

版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/89069949

只是想记录一下做过的题

比赛总地址  http://acm.sdibt.edu.cn/vjudge/contest

2019省赛训练-1

Sample Input
8
10 0
0 2
-3 0
4 2
0 -13
-4 1
-2 -1
3 -1
Sample Output
C
C
P
C
C
P
P
C

题意:• Suppose m2 + n 2 > 0. Then, 〈m, n〉 is a divisor of 〈p, q〉 if and only if the integer m2 + n 2 is a common divisor of mp + nq and mq − np.就是根据这个公式求出除〈1, 0〉, 〈0, 1〉, 〈−1, 0〉, 〈0, −1〉, 〈m, n〉, 〈−n, m〉, 〈−m, −n〉 and 〈n, −m〉之外有没有其他满足的条件,有就输出C,没有就输出P.

#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(LL i=a;i<=b;i++)
#define forj(a,b) for(LL 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 LL M=1e6+7;

int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    LL t;
    cin>> t ;
    while(t--){
        LL m,n,a,b,c;
        cin >> m >> n;
        LL max1=max(fabs(m),fabs(n));
        LL sum=0;
        for(LL i=-max1;i<30000;i++){
            for(LL j=-max1;i*i+j*j<20000;j++){
                if(i*i+j*j>0){
                    LL x=i,y=j;
                    a=x*m+y*n;
                    b=x*n-y*m;
                    c=x*x+y*y;
                    if(a%c==0&&b%c==0&&c!=m*m+n*n&&c!=1){
                        sum++;
                    }
                    if(sum>1)
                        break;
                }
            }
            if(sum>1)
                break;
        }
        if(sum==0)
            cout << "P" << endl;
        else
            cout << "C" << endl;

    }
    return 0;
}

2019省赛训练-2

Sample Input

ABCA BACA
ELLY KRIS
AAAA ZZZZ
Sample Output

0
29
100

题意:给出两个字符串,各自元素可以交换,然后从第一个串到第2个串最少需要几步,A-Z 25步,Z-A 1步。

思路:每个字符串都先按字符串大小排一下序,将第二个串最后一个字符移到前面来,计算一下需要几步,这样经过n(字符串长度)次,求出最小值。

#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(LL i=a;i<=b;i++)
//#define forj(a,b) for(LL 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 LL mod=1e9+7;
int a[111111];
int cmp(char p,char q){

    return p<q;
}
int main()
{
    char s1[55],s2[55];
    while(cin >> s1 >> s2){
        int len = strlen(s1);
        sort(s1,s1+len,cmp);
        sort(s2,s2+len,cmp);
        int min1=MAX,sum=0;
        for(int i=0;i<len;i++){
            sum=0;
            for(int j=0;j<len;j++)
            {
                if(s1[j]>s2[j])
                {
                    sum+=26-(s1[j]-'A'+1)+(s2[j]-'A'+1);
                }
                else
                {
                    sum+=(s2[j]-'A'+1)-(s1[j]-'A'+1);
                }
            }
        if(sum<=min1)
            min1=sum;
        char c=s2[0];
        for(int j=1;j<len;j++){
            s2[j-1]=s2[j];
            }
        s2[len-1]=c;
        }
        cout<<min1<<endl;
    }
    return 0;
}

J. Smallest Difference

Input
2
3
1 2 3
5
2 2 3 4 5
OUt
2
3

 题意:任意挑选x个数,使得这x个数任意两个差的绝对值小于等于1,问x最多有几个。

#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(LL i=a;i<=b;i++)
//#define forj(a,b) for(LL 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 LL M=1e5+7;
const LL mod=1e9+7;
int a[M],b[M],c[M];
set <LL> se;
int main()
{
    // freopen("//home//acm//桌面//in","r",stdin);
    LL t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        se.clear();
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[a[i]]++;
            se.insert(a[i]);
        }
        memset(c,0,sizeof(c));
        set<LL>::iterator it;
        LL e=0;
        for(it=se.begin();it!=se.end();it++)
            c[e++]=*it;
        LL maxx=b[c[0]];
        for(int i=1;i<e;i++)
        {
            LL sum=0;
            if(c[i]-c[i-1]<=1)
                sum=b[c[i]]+b[c[i-1]];
            if(sum>=maxx)
                maxx=sum;
            if(b[c[i]]>=maxx)//第一次没有想到(样例 0 1 3 3 3)
                maxx=b[c[i]];
        }
        cout<<maxx<<endl;
    }
    return 0;
}

2019省赛训练-4

 Lucky 7

Sample Input
4
3 7
4 5 6
3 7
4 7 6
5 2
2 5 2 5 2
4 26
100 1 2 4

Sample Output
No
Yes
Yes
Yes

题意:给出两个数n,b,问接下来的n个数有没有存在加上b能整除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(LL i=a;i<=b;i++)
//#define forj(a,b) for(LL 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 LL M=1e5+7;
const LL mod=1e9+7;
LL a[M];
map<LL,LL>m;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int t,n,x,b;
    cin>>t;
    while(t--)
    {
        int flag=0;
        cin>>n>>b;
        for(int i=0;i<n;i++){
            cin>>x;
            if((x+b)%7==0){
                flag=1;
            }

        }

        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}

B - King of Karaoke

Sample Input

2
4
1 2 3 4
2 3 4 6
5
-5 -4 -3 -2 -1
5 4 3 2 1
Sample Output

3
1

题意:有两组数,问加上一个x,使得两组数里面相同的最多,求这个相同最多的个数。

思路:直接计算对应两个的差,放到map中,在求个数的最大值。 

#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(LL i=a;i<=b;i++)
//#define forj(a,b) for(LL 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 LL M=1e5+7;
const LL mod=1e9+7;
int a[M],b[M];
map<int,int>m;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        m.clear();
        for(int i=0;i<n;i++){
            cin>>a[i];
        }

        for(int i=0;i<n;i++){
            cin>>b[i];
            int x=b[i]-a[i];
            m[x]++;
        }

        map<int,int>::iterator it;
        int maxx=-1;
        for(it=m.begin();it!=m.end();it++)
        {
            if(it->second>=maxx)
                maxx=it->second;
        }
        cout<<maxx<<endl;

    }

    return 0;
}

A - Peak

Sample Input

7
5
1 5 7 3 2
5
1 2 1 2 1
4
1 2 3 4
4
4 3 2 1
3
1 2 1
3
2 1 2
5
1 2 3 1 2
Sample Output

Yes
No
No
No
Yes
No
No

题意:问有没有存在这样的情况,前面是单调递增的,后面是单调递减的。

#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(LL i=a;i<=b;i++)
//#define forj(a,b) for(LL 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 LL M=1e5+7;
const LL mod=1e9+7;
LL a[M],b[M];
map<LL,LL>m;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    LL t;
    scanf("%d",&t);
    while(t--){
        LL n,in=0,de=0,flag=0;
        scanf("%d",&n);
        for(LL i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
         for(LL i=1;i<=n;i++){
            if(i>1&&a[i]<a[i-1]){
                    flag=1;
            }
            if(a[i]>=a[i-1]&&i>1)
            {   
                if(a[i]>a[i-1])
                    in++;
                if(flag){
                    flag=0;
                break;

                }
            }
        }
        if(flag&&in)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }



    return 0;
}

J - CONTINUE...?

Sample Input

5
1
1
2
10
3
101
4
0000
7
1101001
Sample Output

-1
-1
314
1221
3413214

题意:0代表女生,1代表男生,分成4个组,G1,G2,G3,G4 ,要求G1,G2 放女生,其他两个放男生,每个的价值是在字符串的位置,现在要求是否可以分成组,使得G1 G3价值的和等于其他两个的和。

思路:和为奇数不可能分组,偶数时分成和的一半.

(卡了好多次…………)

#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(LL i=a;i<=b;i++)
//#define forj(a,b) for(LL 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 LL M=1e5+7;
const LL mod=1e9+7;
char a[M];
LL b[M];
int main()
{
    LL t;
    scanf("%lld",&t);
    while(t--)
    {
        mem(b,0);
        LL n;
        LL sum=0;
        scanf("%lld",&n);
      //  getchar();
        scanf("%s",a);
        sum=(n+1)*n/2;
        if(sum%2==1){
            printf("-1\n");
        }
        else {
            sum/=2;
            for(LL i=n-1;i>=0;i--){
               if(sum==0)
                    break;
                if(sum>=i+1){
                    b[i]=1;
                    sum-=i+1;
                }
                else {
                    b[sum-1]=1;
                    sum=0;
                    break;
                }
            }
            for(LL i=0;i<n;i++){
                if(b[i]){
                    if(a[i]=='0'){
                        printf("1");
                    }
                    else
                        printf("3");
                }
                else {
                    if(a[i]=='0')
                        printf("2");
                   else
                        printf("4");
                }
            }
            printf("\n");
        }



    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/89069949