上海市计算机学会2020年7月月赛(丙组)
 发布时间 
 阅读量: 
 阅读量 
第一道题:盈亏问题 AC
 #include <iostream>
    
 #include <algorithm>
    
 using namespace std;
    
 int a, b, t;
    
 int main() {
    
 	scanf("%d%d%d", &t, &a, &b);
    
 	printf("%d %d", a+b, t*(a+b)-a);
    
 	return 0;
    
 }
        第二道题:感应门 AC
 #include <iostream>
    
 #include <algorithm>
    
 using namespace std;
    
 int n, x, t1 = 0;
    
 int main() {
    
 	scanf("%d%d", &n, &x);
    
 	int t[n+2];
    
 	for (int i = 1; i <= n; i++)
    
 		scanf("%d", t + i);
    
 	for (int i = 2; i <= n; i++) {
    
 		if (t[i-1]+x >= t[i])
    
 			t1 += t[i] - t[i-1];
    
 		else t1 += x;
    
 	}
    
 	printf("%d", t1 + x);
    
 	return 0;
    
 }
        第三道题:数根 AC
 #include <iostream>
    
 #include <algorithm>
    
 using namespace std;
    
 string s;
    
 int gsum(int x) {
    
 	int sum = 0;
    
 	while(x) {
    
 		sum += x % 10;
    
 		x /= 10;
    
 	}
    
 	return sum;
    
 }
    
 int grood(int y) {
    
 	if(y < 10)
    
 		return y;
    
 	else {
    
 		int sum = gsum(y);
    
 		return grood(sum);
    
 	}
    
 }
    
 int main() {
    
 	cin >> s;
    
 	int len = s.size(), sum = 0;
    
 	for(int i = 0; i < len; i++)
    
 		sum += s[i] - '0';
    
 	printf("%d", grood(sum));
    
 	return 0;
    
 }
        第四道题:倍数区间 AC
 #include <iostream>
    
 #include <algorithm>
    
 using namespace std;
    
 typedef long long LL;
    
 const int N = 2e5 + 7;
    
 LL sum[N], ct[N], n, k, ans;
    
 int main() {
    
 	scanf("%lld%lld", &n, &k);
    
 	for(int i = 1; i <= n; i++) {
    
 		LL t;
    
 		scanf("%lld", &t);
    
 		sum[i] = (sum[i-1]+t) % k;
    
 		ans += ct[sum[i]];
    
 		ct[sum[i]]++;
    
 	}
    
  
    
 	printf("%lld\n", ans + ct[0]);
    
 	return 0;
    
 }
        第五道题:闯关升级 AC
 #include <iostream>
    
 #include <algorithm>
    
 using namespace std;
    
 typedef long long LL;
    
 const int N = 1e5 + 7;
    
 LL n, t, a[N], b[N], mx = -1;
    
 signed main() {
    
 	scanf("%lld%lld", &n, &t);
    
 	for (LL i = 1; i <= n; i++) {
    
 		scanf("%lld", a + i);
    
 		a[i] += a[i-1];
    
 	}
    
 	for (LL i = 1; i <= n; i++) {
    
 		scanf("%lld", b + i);
    
 		b[i] += b[i-1];
    
 	}
    
 	for (LL i = 0; i <= n; i++) {
    
 		if (a[i] > t) break;
    
 		mx = max(upper_bound(b+1, b+n+1, t-a[i]) - (b+1) + i, mx);
    
 	}
    
 	printf("%lld\n", mx);
    
 	return 0;
    
 }
        若有更好的解,欢迎评论或私信与我~
全部评论 (0)
 还没有任何评论哟~ 
