CF Round929 div3

这篇文章介绍了ACM编程竞赛中的五道题目,涉及数组操作、数字处理、模运算、整数计算等,包括求绝对值之和、调整数组使余数为特定值、计数满足条件的元素等。

1933A--Turtle Puzzle: Rearrange and Negate

SOLVE: To summerize, this problem provides us with two arbitrary operations to alter an array. But after we've understood the panorama, it's not difficult to think of a pretty easy way to deal with it: that is summing all the absolute values of the inputs. (I think the solution may seem a little monotonous.)

#include <bits/stdc++.h>
using namespace std;

int testNum, n;

int main()
{
	scanf("%d", &testNum);
	while(testNum--)
	{
		int sum = 0;
		int temp;
		scanf("%d", &n);
		for(int i = 0; i < n; i++)
		{
			scanf("%d", &temp);
			sum += abs(temp);
		}
		printf("%d\n", sum);
	}
	return 0;
}

1933B--Turtle Math: Fast Three Task

SOLVE: This problem needs deliberate consideration. May as well consider the following situations: First, no doubt, when the sum of the elements from the original array is divisive by 3, then you need 0 step. Second, when the remainder of the division is 2, you can take the second method, which is to increase an element by 1. Third, presently the remainder can only be 1, so if any of the input value whose remainder is 1 after divided by 3 exists, then just deleting it can suceed, so the step number is also 1. Lastly, unfortunately it's the worst situation where the remainder being 1 and no such input value whose remainder is 1 after divided by 3 existed, what we can do is to repeatedly increase any of the elements by 1 twice, then the problem is solved.

#include<bits/stdc++.h>
using namespace std;

int testNum, n;

int main()
{
	scanf("%d", &testNum);
	while(testNum--)
	{
		scanf("%d", &n);
		int temp, sum=0, decision=0;
		for(int i = 0; i < n; i++)
		{
			scanf("%d", &temp);
			sum += temp;
			if(temp % 3== 1) decision = 1;
		}
		if(sum % 3 == 0) printf("0\n");
		else if(sum % 3 == 2) printf("1\n");
		else if(decision) printf("1\n");
		else printf("2\n");
	}
	return 0;
}

***A Little Trick: Used to untie the bond between the input stream and the output stream in order to increase the efficiency. Click this link for detailed information.

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

1933C--Turtle Fingers: Count the Values of k

SOLVE: To be continued...

#include<bits/stdc++.h>
using namespace std;

int testNum;

int main()
{
	cin >> testNum;
	while(testNum--)
	{
		int a, b, l;
		cin >> a >> b >> l;
		set<int> ss;
		for(int i = 1; l % i == 0; i *= a)
			for(int j = 1; l % (i*j) == 0; j *= b)
				ss.insert(l/(i*j));
		cout<<ss.size()<<endl;
	}
	return 0;
}

1933D--Turtle Tenacity: Continual Mods

SOLVE: To be continued...

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int testNum;

int main()
{
	cin >> testNum;
	while(testNum--)
	{
		ll n;
		cin >> n;
		vector<ll> v(n);
		for(auto &it : v)
			cin >> it;
		ll gcd = 0;
		for(int i = 0; i < n; i++)
			gcd = __gcd(gcd, v[i]);		//__gcd():标准库函数,取最大公因数
		ll cnt = count(v.begin(), v.end(), gcd);
		cout << (cnt <= 1 ? "YES\n" : "NO\n");
	}
	return 0;
}

1933E--Turtle vs. Rabbit Race: Optimal Trainings

SOLVE: To be continued...

#include <bits/stdc++.h>
using namespace std;

int n, m, k, l, t, u;
long long g[100010];
void solve();

int main()
{
	scanf("%d", &t);
	while(t--) solve();
	return 0;
}

void solve()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%lld", &g[i]);
		g[i] += g[i-1];
	}
	scanf("%d", &m);
	while(m--)
	{
		scanf("%d%d", &l, &u);
		k = lower_bound(g+l, g+n+1, u+g[l-1]) - g;
		if(k==l || k<=n && g[k]-g[l-1]-u-1<u-g[k-1]+g[l-1]) printf("%d ", k);
		else printf("%d ", k-1);
	}
	putchar('\n');
}

1933F--Turtle Mission: Robot and the Earthquake

SOLVE: To be continued...

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll testcase;
	cin >> testcase;
	while(testcase--)
	{
	    ll n, m;
	    cin >> n >> m;
	    ll a[n][m];
	    for(int i = 0; i < n; i++) 
			for(int j = 0; j < m; j++) 
				cin >> a[i][j];
	    ll dp[n][m];
	    for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++) 
				dp[i][j] = 2e18;
	    dp[0][0] = 0;
	    for(int j=0;j<m-1;j++) 
			for(int ii=0;ii<4*n;ii++)
			{
		    	int i = ii % n;
		    	if(a[(i+1)%n][j] == 0 && a[(i+2)%n][j] == 0) 
					dp[(i+2)%n][j] = min(dp[(i+2)%n][j], dp[i][j]+1);
		    	if(a[(i+1)%n][j+1] == 0) 
					dp[(i+1)%n][j+1] = min(dp[(i+1)%n][j+1], dp[i][j]+1);
    		} 
    	ll ans = 2e18;
	    for(int i = 0; i < n; i++)
		{
	    	ll g = (n - 1 + dp[i][m-1]) % n;
	    	ans = min({ans, dp[i][m-1] + abs(g-i), dp[i][m-1]+abs(g-i-n), dp[i][m-1]+abs(g-i+n)});
	    }
    if(ans > 1e18) ans = -1;
    cout << ans << "\n";
	}
}

1933G--Turtle Magic: Royal Turtle Shell Pattern

SOLVE: To be continued...

#include<bits/stdc++.h>
using namespace std;

bool mask[4][4]={
    {0, 0, 1, 1},
    {0, 1, 1, 0},
    {1, 1, 0, 0},
    {1, 0, 0, 1}
};
set<int> x, y;

int main()
{
    cin.tie(0) -> sync_with_stdio(0);
    int t, n, m, q, r, c;
    string s;
    bool b;
    cin >> t;
    while(t--)
    {
        cout << "8\n";
        cin >> n >> m >> q;
        for(int i = 0; i < 4; i++) 
            x.insert(i), y.insert(i);
        while(q--)
        {
            cin >> r >> c >> s;
            b = (s == "square");
            for(int i = 0; i < 4; i++)
            {
                if(b^(r%2) != mask[i][c%4]) x.erase(i);
                if(b^(c%2) != mask[i][r%4]) y.erase(i);
            }
            cout << x.size()+y.size() << '\n';
        }
    }
}

### Codeforces Round 980 (Div. 2) 比赛信息 Codeforces Round 980 (Div. 2) 是一场面向国际编程爱好者的在线竞赛,吸引了大量来自不同国家的参赛者参与。这场比赛通常包含多个难度级别的题目,旨在测试选手们的算法设计能力和编码技巧。 #### 比赛时间与平台 比赛于特定日期在Codeforces平台上举行,持续时间为两小时。在此期间内,参与者需解决尽可能多的问题来获得高分并争取更好的排名位置[^2]。 ### 题目解析:C - Concatenation of Arrays 对于给定的任务——数组连接问题,目标是从两个长度相等但元素可能不同的整数序列出发,在满足一定条件下构建一个新的组合形式。具体来说: - 输入描述了一个由正整数组成的列表`q[]`以及两个参数`n`和`m`。 - 要求通过某种方式调整这些数值的位置关系使得最终形成的结构能够达到预期效果。 为了实现上述目的,可以采用线性扫描的方法来进行处理而不是复杂的二分查找策略。以下是简化后的解决方案概述及其对应的伪代码表示: 当遍历整个数据集时计算累积值,并判断当前状态下能否形成合法配置;一旦发现符合条件的情况立即更新最优解直至完成全部迭代过程为止。 ```cpp #include <iostream> #include <algorithm> using namespace std; const int N = 1e5 + 7; int q[N]; bool check(int x, int n, int m) { int res = 0; for (int i = 1; i <= x; ++i) { if (i != x) res += q[i]; else res += (n - i + 1) * q[i]; } return res >= m; } void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> q[i]; sort(q + 1, q + 1 + n); int l = 1, r = n; while (l < r) { int mid = l + r >> 1; if (check(mid, n, m)) r = mid; else l = mid + 1; } cout << l - 1 + m << &#39;\n&#39;; } ``` 此段程序实现了对输入数据的有效分析,并利用简单的逻辑运算得出正确答案。值得注意的是,尽管最初考虑过使用二分法优化性能,但实际上仅需一次完整的顺序访问就能解决问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值