2019年安徽大学ACM/ICPC实验室新生赛(公开赛)

A 素数分布

解法:暴力枚举

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int  T;
bool f(int x){
    if(x == 1) return false;
    for(int i = 2 ; i * i <= x ; ++ i){
    if(x % i == 0) return false;
    }
    return true;
}
int main()
{
    scanf("%d", &T);
    while(T --){
            int n;
        scanf("%d", &n);
        int cnt = 0;
        for(int i = 2 ; i <= n ; ++ i){
            if(f(i)) cnt ++;
        }
        cout << cnt << endl;
    }
    return 0;
}

B 食物分配

解法:只有最小加次小等于次大等于最大才成立

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int  T;
int a[10];
int main()
{
    scanf("%d", &T);
    while(T --){
        int sum = 0;
        for(int i = 1 ; i <= 4 ; ++ i) scanf("%d", &a[i]), sum += a[i];
        sort(a+1,a+1+4);
        if(sum%3!=0) cout << "-1" << endl;
        else{
            if(a[1]+a[2] == a[3] && a[3] == a[4]) cout << a[3] << endl;
            else cout << "-1" << endl;
        }
    }
    return 0;
}

C AHUICPC (Easy Version)

解法:特殊构造n=10的情况,其他情况只需在末尾加n个C即可

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int  T, n;
 
int main()
{
    scanf("%d", &n);
    if(n <= 9){
        printf("AHUICP");
    for(int i = 1 ; i <= n ; ++ i) cout << "C";
    }
    else{
        printf("AHUICCPCCCCC");
    }
    return 0;
}

D 不定方程

蜜汁题意,就是两个不互素输出-1(题意太鬼畜了),否则输出两数之积

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int  T, n;
ll x, y;
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%lld %lld", &x, &y);
        ll gcd = __gcd(x, y);
        x = x/gcd; y = y/gcd;
        if(gcd != 1) cout << "-1" << endl;
        else cout << y << ' ' << x << ' ' << y * x * gcd << endl;
    }
    return 0;
}

E 蕊蕊识数

解法:答案只会有2或3的情况,判完2之后若不满足直接输出3.(ps:能被3整除的经过题中操作永远都能被3整除,不能的永远不能,因为被3整除的充要条件为各位数和能被3整除)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int T;
char s[maxn];
int cal(int x){
    int ans = 0;
    while(x){
        ans += x % 10;
        x /= 10;
    }
    return ans;
}
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%s", s);
        int n = strlen(s);
        int sum = 0;
        for(int i = 0 ; i < n ; ++ i){
            sum += s[i] - '0';
        }
        if((s[n-1]-'0')%2 == 0){
            while(sum % 2 == 0){
                sum = cal(sum);
                if(sum < 10) break;
            }
            if(sum / 10 == 0 && sum % 2 == 0) cout << "2" << endl;
            else cout << "3" << endl;
        }
        else{
            while(sum % 2 != 0){
                sum = cal(sum);
                if(sum < 10) break;
            }
            if(sum / 10 == 0 && sum % 2 != 0) cout << "2" << endl;
            else cout << "3" << endl;
        }
    }
    return 0;
}

F 蕊蕊乘车去上学

解法:对于无穷长的位置,点落在a的概率是a/(a+b),所以a的期望是a×a/(a+b),因为从a上车一定是a个人,b的情况和a也差不多所以最后是(a×a+b×b)/(a+b)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
ll n;
double a, b;
int main()
{
    scanf("%lf %lf", &a, &b);
    printf("%.2lf", (a*a+b*b)/(a+b));
    return 0;
}

G AHUICPC (Hard Version)

解法:考虑对于原来的串前面每次加一个AH会多出(AH的数量,这里可以手推一下),那么增长级别是(i+1)*i/2,先找到i最大的i使得(i+1)*i/2
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n;
int main()
{
    scanf("%d", &n);
    int t = 1;
    if(n == 1) printf("AHUICPC");
    else{
        int t = 1;
        for(int i = 1 ; ; ++ i){
            if((i+1) * i / 2 > n){
                t = i - 1;
                break;
            }
        }
        int k = n-(t+1)*t/2;
        for(int i = 1 ; i <= t ; ++ i){
            if(i == t-k+1){
                cout << "AA";
                cout << "H";
            }
            else cout << "AH";
        }
        cout << "UICPC" << endl;
    }
    return 0;
}

H 无尽大军

解法:答案为能被分解的素因子之和。因为比如考虑60(60=223*5),倒推在30花费2变成60, 在15花2变30, 在5的时候(先把5变10, 再把10变15), 对于5(素数)只能从1 2 3 4 5上来。所以答案是2+2+3+5 = 12;

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e6 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
ll n;
int main()
{
    scanf("%lld", &n);
    int cnt = 0;
    ll p = 1e9;
    int flag = 0;
	ll ans = 0;
    for(ll i = 2 ; i * i <= n ; ++ i){
        while(n % i == 0){
            ans += i;
            n /= i;
        }
    }
    if(n > 1) cout << n + ans;
    else cout << ans;
 
    return 0;
}

你可能感兴趣的:(比赛题解)