山西省第三届程序设计大赛

A.  消灭zbt

题解:只有所有的事件成功,才不会被消灭. 所以累乘就好

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n; 
	double ans = 1.0;
	while(n--){
		double k;
		cin >> k;
		ans = ans * k;
	}
	printf("%.6lf\n", ans);
	return 0;
}

B.数字混合

题解:对于任意多的300 ,只要 大于等于300 ,一律看成300, 不足300 的用 1 来弥补

#include <bits/stdc++.h>
using namespace std;
int main(){
	int m, n;
	cin >> m >> n; 
	if(n >= m % 300){         //  只要 n 大于 m % 300 就可以
		cout << "That's too easy!" << endl;
	}
	else{
		cout << "ZBT is so vegetable that _AiR_H can't do it!" << endl; 
	}
	return 0;
}

C.毕达哥拉斯学派的秘密

题解:将 36进制字符串 转换为 10 进制 然后对 n 取余

因为mod 最大为 1e+9 所以开 long long(错了4次)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	while(cin >> n){
		ll k, w , f = 1;
		string s;
		cin >> s;
		int l = s.size();
		ll ans = 0;
		for(int i = l-1; i >= 0; i--){            // 对字符串转换为 10 进制
			if(s[i] >= '0' && s[i] <= '9'){
				k = s[i] - '0';
			}
			else{
				k = s[i] - 'A' + 10;
			}
			ans = (ans + (f * k)) % n;       // 逐步对 n 取余 并不会影响答案
			f = f * 36 % n;
		}
		cout << ans % n << endl;
	}
	return 0;
}

D.灰哥的烦恼

题解:题目就是要求 数组中的元素互不相同且最小为 a[i], 总和不超过 k (注意数据范围)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	ll k;
	while(scanf("%d%d", &n, &k) != EOF){
		int a[100005];
		for(int i = 1; i <= n; i++){
			scanf("%d", &a[i]);
		}
		sort(a+1, a+1+n);            // 先进行排序
		ll ans = a[1];
		for(int i = 2; i <= n; i++){
			if(a[i] <= a[i-1]){                 // 如果相同那么就是前一个加一
				a[i] = a[i-1] + 1;
			}
			ans = ans + a[i];                // 计算总和
		}
		if(ans <= k){
			printf("%lld\n", ans);
		}
		else{
			printf("Dalao de yao qiu tai gao le , QAQ\n");
		}
	}
	return 0;
}

E.一道大水题

题解:按照题目要求模拟就好

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		ll n;
		scanf("%lld", &n);
		if(n == 0){                // 当 n 等于 0 ,则输出 1e18 - 1(0乘任何数都为0)
			printf("999999999999999999\n");
			continue;
		}
		if(n > 0){                // 当 n 大于 0
			for(int i = 2; i <= n; i = i + 2){     // 从2开始,每次递增为2
				if(n % i == 0 && n / i % 2 != 0){   // 判断 n % i 是否为整数且 n/i 是奇数
					printf("%lld\n", n / i);
					break;
				}
			}
		}
		else{                // 当 n 小于 0 ,则 x 就是n本身,输出 1
			printf("1\n");
		}
	}
	return 0;
}

F.黑客大战

题解:欧拉函数,求小于n的正整数中与n互质的数的数目(因为约分后会重复)

例如:2/4  == 1/2       2为4的因子此为重复现象

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1000005;
int e[maxn];
void solve(){    
   e[1] = 1;
   for(int i = 2; i < maxn; i++){
      e[i] = i;
   }
   for(int i = 2;i < maxn;i++){
      if(e[i] == i){
         for(int j = i; j < maxn; j= j + i){
            e[j] = e[j] / i * (i-1);
         }
      }
   }
}
int main(){
	solve();
	int n;
	scanf("%d", &n);
	ll ans = 0;
	for(int i = 2; i <= n; i++){
		ans = ans + e[i];
	}
	printf("%lld\n", ans*2);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值