2019年湘潭大学程序设计竞赛(重现赛)

2019年湘潭大学程序设计竞赛(重现赛)

A:Who‘s better?

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n1,p1,s1,n2,p2,s2;
    cin>>n1>>p1>>s1;
    cin>>n2>>p2>>s2;
    if(n1!=n2){
        if(n1>n2)cout<<"1\n";
        else cout<<"2\n";
        return 0;
    }
    if(p1!=p2){
        if(p1<p2)cout<<"1\n";
        else cout<<"2\n";
        return 0;
    }
    if(s1!=s2){
        if(s1<s2)cout<<"1\n";
        else cout<<"2\n";
        return 0;
    }
    cout<<"God\n";
    return 0;
}

B:Number

#include<bits/stdc++.h>
using namespace std;
int t,n;
int main(){
    scanf("%d",&t);
    while(t--){
        int ans=0;
        scanf("%d",&n);
        while(n>1){
            int p=n%10;
            if(p==0){
                ans++;
                n/=10;
            }
            else{
                n=n+10-p;
                ans=ans+10-p;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C:Math Problem

(a*k+1)3=a3*k3+3a2k2+3ak+1=(a2*k3+3a1k2+3k)a+1=a*x+1;

即(a*k+1)的3次方也是a的倍数+1;

#include<bits/stdc++.h>
using namespace std;
int t,l,r;

int main(){

    scanf("%d",&t);
    while(t--){
        long long ans=0;
        scanf("%d%d",&l,&r);
        int p=l/192,q=r/192;
        if(l%192>1)p++;
        if(r%192<1)q--;
        for(int i=p;i<=q;i++){
            ans=ans+(long long )i*192+1;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

D:Stone

每次取最大堆与任一相邻合并,结果 : 总和-max

#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+10;
const int N=1e5;
int t,n;
long long a[N];

int main(){
    scanf("%d",&t);
    while(t--){
        long long ans=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%lld",&a[i]);
        }
        sort(a,a+n);
        for(int i=0;i<n-1;i++){
            ans+=(long long )a[i];
        }

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

F:Black & White

二分+前缀和

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int t,n,m;
char str[N];
int p[N];
int solve(int x){
    for(int i=0;i+x<=n;i++){
        if(p[i+x]-p[i]+m>=x||(i+x-p[i+x])-(i-p[i])+m>=x) return 1;
    }
    return 0;
}
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%s",&n,&m,str);
        memset(p,0,sizeof(p));
        for(int i=1;i<=n;i++){
            if(str[i-1]==‘1‘){
                p[i]=p[i-1]+1;
            }
            else{
                p[i]=p[i-1];
            }
        }
        int l=0,r=n,mid;
        while(l<=r){
            mid=(l+r)/2;
            if(solve(mid)) l=mid+1;
            else r=mid-1;
        }
        printf("%d\n",r);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/YJing814/p/10810392.html

时间: 2024-08-30 00:20:01

2019年湘潭大学程序设计竞赛(重现赛)的相关文章

第八届福建省大学生程序设计竞赛-重现赛

第八届福建省大学生程序设计竞赛-重现赛 B   计算几何 题意:问两个三角形是相交.包含还是相离. tags:套板子..求出相交的面积,再判断一下 /* 多边形相交面积模板 */ #define maxn 510 const double eps=1E-8; int sig(double d){ return(d>eps)-(d<-eps); } struct Point{ double x,y; Point(){} Point(double x,double y):x(x),y(y){} b

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 1008(hdu 5929)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5929 Problem Description Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack: ? PUSH x: put x on the top of the stack, x must be 0 or 1.? POP

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 1003

链接http://acm.hdu.edu.cn/showproblem.php?pid=5924 题意:根据公式求C,D 解法:打表找规律 #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t,cnt=1; scanf("%d",&t); while(t--) { ll a,b; scanf("%I64d%I64d",&a

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 1005

链接http://acm.hdu.edu.cn/showproblem.php?pid=5926 题意:给我们一个矩阵,问你根据连连看的玩法可以消去其中的元素 解法:连连看怎么玩,就怎么写,别忘记边界 #include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 1001

链接http://acm.hdu.edu.cn/showproblem.php?pid=5922 题意:最小生成树,但边的权值是连接两点的最小公倍数 解法:不要真的写最小生成树啦,只要其他点和第一点相连,边的权值就是最小的,相加就好了 #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t,cnt=1; scanf("%d",&t); while(t-

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 1008

链接http://acm.hdu.edu.cn/showproblem.php?pid=5929 题意:给你一种数据结构以及操作,和一种位运算,最后询问:从‘栈’顶到低的运算顺序结果是多少 解法:根据位运算,发现出现0,结果就是1,那么就记录两端0的位置就好,中间不管出现什么,结果大部分都是1,考虑还有反转操作,使用双端队列,用flag标记反转后的情况,然后根据需要添加元素记录位置,最后根据标记,出现元素等进行讨论计算 #include <iostream> #include <dequ

RunningMan【第六届福建省大学生程序设计竞赛-重现赛】

RunningMan Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original ID: 2221 64-bit integer IO format: %I64d      Java class name: Main Prev Submit Status Statistics Discuss Next ZB loves watching RunningMan! There's a ga

2013年北京师范大学新生程序设计竞赛网络赛--D. Number theory(模拟取余)

D. Number theory Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status PID: 34055 Font Size:  +   - 数学不仅是简单而且是美的.数学很有趣,但是数学中也有很多难题,比如哥德巴赫猜想.各种欧拉定理.拉格朗日中值定理.费马定理等.今天小若遇

2019河北省大学生程序设计竞赛(重现赛) L题-smart robot(深度优先搜索)

题目链接:https://ac.nowcoder.com/acm/contest/903/L 题意:给你 n * n的方阵,你可以从任意一个数字开始走,可以走上下左右四个方向,走过的数字会被拼合,拼合的数字没有前导0,问最小不能拼合出来的数字是多少? 思路:开始就认为是一道深搜题,后面自己想太多就没去试,醉了orz! 这题就是把每个数字作为起点开始搜索,把已经搜索过的数字进行标记,然后从0开始检索,输出第一个未出现的数字就是答案.搜索的话我代码是搜5位数的所有组合,事实上这道题搜索3位数的所有组