首页 > 其他分享 >Codeforce Round 929(Div.3)

Codeforce Round 929(Div.3)

时间:2024-02-29 09:11:27浏览次数:19  
标签:std return int cin 929 while solve Codeforce Div.3

Codeforces Round 929 (Div.3)刷题记录

A.Turtle Puzzle: Rearrange and Negate

// Problem: A. Turtle Puzzle: Rearrange and Negate
// Contest: Codeforces - Codeforces Round 929 (Div. 3)
// URL: https://codeforces.com/contest/1933/problem/0
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Date:2024-02-27 22:35:53
// Author:hblgzsx
// 借鉴思路:自己
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>


void solve()
{
	int n; std::cin >> n;
	std::vector<int> a(n);
	long long ans = 0;
	for(auto &x : a) std::cin >> x, ans += abs(x);
	std::cout << ans << "\n";
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

B.Turtle Math: Fast Three Task

// Problem: B. Turtle Math: Fast Three Task
// Contest: Codeforces - Codeforces Round 929 (Div. 3)
// URL: https://codeforces.com/contest/1933/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Date:2024-02-27 22:40:23
// Author:hblgzsx
// 借鉴思路:自己
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>


void solve()
{
	int n; std::cin >> n;
	std::vector<int> a(n);
	int flag[3] = {0, 0, 0};
	int sum = 0;
	for(auto &x : a)
	{
		std::cin >> x;
		sum += x;
		if(x % 3 == 2) flag[2] = 1;
		if(x % 3 == 1) flag[1] = 1;
	}
	int v = sum % 3;
	if(v == 0) std::cout << flag[v] << "\n";
	else
	{
		if(v == 1)
		{
			if(flag[1]) std::cout << 1 << "\n";
			else std::cout << 2 << "\n";
		}
		else if(v == 2)
		{
			std::cout << 1 << "\n";
		}
	}
	
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

C.Turtle Fingers: Count the Values of k

#include<bits/stdc++.h>
#define int long long

int qmi(int a, int k)
{
	int res = 1;
	while(k)
	{
		if(k & 1) res *= a;
		a *= a;
		k >>= 1;
	}
	return res;
}
void solve()
{
	int a, b, l;
	std::cin >> a >> b >> l;
	std::set<int> st;
	for(int x = 0; qmi(a, x) <= l; x++)
	{
		for(int y = 0; qmi(b, y) <= l; y++)
		{
			int k = qmi(a, x) * qmi(b, y);
			if(l >= k  && l % k == 0)
			{
				st.insert(l / k);
			}
			else if(l < k) break;
		}
	}
	std::cout << st.size() << "\n";
}
signed main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

D.Turtle Tenacity: Continual Mods

#include<bits/stdc++.h>


void solve()
{
	int n; std::cin >> n;
	std::vector<int> a(n);
	std::cin >> a[0];
	int res = a[0];
	for(int i = 1; i < n; i++) 
	{
		std::cin >> a[i];
		res = std::__gcd(res, a[i]);		
	}
	for(int i = 0; i < n; i++)
	{
		a[i] /= res;
	}
	std::sort(a.begin(), a.end());
	int x = std::upper_bound(a.begin(), a.end(), a[0]) - a.begin();
	if(x >= 2 && a[0] == 1) std::cout << "NO\n";
	else if(x >= 2 && res == 1) std::cout << "YES\n";
	else std::cout << "YES\n";
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

E.Turtle vs. Rabbit Race: Optimal 训练

#include<bits/stdc++.h>


void solve()
{
    int n; std::cin >> n;
    std::vector<int> a(n + 1, 0);
    for(int i = 0; i < n; i++)
    {
        std::cin >> a[i + 1];
        a[i + 1] += a[i];
    }
    int q;
    std::cin >> q;

    while(q--)
    {
        int l, u;
        std::cin >> l >> u;
        int L = l, R = n;
        while(L + 1 < R)
        {
            int mid = L + R >> 1;
            if(a[mid] - a[l - 1] > u) R = mid;
            else L = mid;
        }
        int rest = u - (a[R - 1] - a[l - 1]);
        int Rint = a[R] - a[R - 1];
        int rest1 = Rint - rest;
        rest1--;
        if(rest1 < rest)
        {
            std::cout << R << " ";
        }
        else if(R <= l) std::cout << l << " ";
        else std::cout << R - 1 << " ";
    }
    std::cout << "\n";
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

F.Turtle Mission: Robot and the Earthquake

#include<bits/stdc++.h>
const int N = 1e3 + 10, INF = 0x3f3f3f3f;
int a[N][N];
int vis[N][N];
void solve()
{
	int n, m; std::cin >> n >> m;
	// std::vector<std::vector<int>> vis(n + 1, std::vector<int> (m + 1, -1));
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			std::cin >> a[i][j];
			vis[i][j] = -1;
		}
	}
	
	std::queue<std::pair<int,int>> q;
	vis[0][0] = 0;
	q.push({0, 0});
	int ans = INF;
	
	while(q.size())
	{
		auto [x,  y] = q.front();
		q.pop();
		if(y == m - 1)
		{
			ans = std::min(ans, vis[x][y] + ((x - n + 1 - vis[x][y]) % n + n) % n);
		}
		
		int tx = (x + 1) % n, ty = y + 1;
		if(ty <= m + 1 && a[tx][ty] == 0 && vis[tx][ty] == -1)
		{
			vis[tx][ty] = vis[x][y] + 1;
			q.push({tx, ty});
		}
		
		tx = (x + 2) % n, ty = y;
		if(a[(x + 1) % n][y] == 0 && a[tx][ty] == 0 && vis[tx][ty] == -1)
		{
			vis[tx][ty] = vis[x][y] + 1;
			q.push({tx, ty});
		}
	}
	
	if(ans == INF) ans = -1;
	std::cout << ans << "\n";
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

G.Turtle Magic: Royal Turtle Shell Pattern

#include<bits/stdc++.h>


void solve()
{
	int n, m, q;
	std::cin >> n >> m >> q;
	auto find = [&](int x, int y, int k)
	{
		if(k < 4)
		{
			y += k;
			if(x % 2 == 1)
			{
				return y % 4 == 0 || y % 4 == 3;
			}
			else
			{
				return y % 4 == 1 || y % 4 == 2;
			}
		}
		else 
		{
			x += k - 4;
			if(y % 2 == 1)
			{
				return x % 4 == 0 || x % 4 == 3;
			}
			else
			{
				return x % 4 == 1 || x % 4 == 2;
			}
		}
	};
	
	int flag[8] = {0};
	int ans = 8;
	std::cout << ans << "\n";
	while(q--)
	{
		int x, y; std::cin >> x >> y;
		std::string s;
		std::cin >> s;
		int t = (s[0] == 's');
		for(int i = 0; i < 8; i++)
		{
			if(flag[i] == 0)
			{
				if(find(x, y, i) != t)
				{
					flag[i] = 1;
					ans--;
				}	
			}
		}
		std::cout << ans << "\n";
	}
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1; std::cin >> t;
	while(t--) solve();
	return 0;
}

标签:std,return,int,cin,929,while,solve,Codeforce,Div.3
From: https://www.cnblogs.com/hblgzsx/p/18042649

相关文章

  • Codeforces Round 929 (Div. 3)
    CodeforcesRound929(Div.3)A-TurtlePuzzle:RearrangeandNegate代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondusingi128=__int128_t;usingpiii=pa......
  • 13 Codeforces Round 886 (Div. 4)G. The Morning Star(简单容斥)
    G.TheMorningStar思路:用map记录x,y,以及y-x、y+x从前往后统计一遍答案即可公式\(ans+=cnt[x]+cnt[y]-2*cnt[x,y]+cnt[y+x]+cnt[y-x]\)\(cnt[x]+cny[y]-2*cnt[x,y]\)是统计坐标轴方向的,-2倍是需要把本身这个点给减去容斥是减一倍,这里还需要把自己给挖掉\(cnt[y+x]+cnt[y......
  • Codeforces 264E Roadside Trees
    首先考虑时间增长的问题,设第\(i\)棵树的种植时间为\(t_i\)。那么第\(x\)棵树比第\(y\)棵树高就是\(h_x+(t_y-t_x)>h_y\),也就是\(h_x-t_x>h_y-t_y\)。所以可以直接用\(h_i-t_i\)当作第\(i\)棵树的高度,即\(h'_i\leftarrowh_i-t_i\)。对于增加,考虑......
  • CodeForces 1844H Multiple of Three Cycles
    洛谷传送门CF传送门首先环是不用管的,只用判环长是否为\(3\)的倍数即可。考虑设\(f(x,y,z)\)表示\(x\)个\(1\)链,\(y\)个\(2\)链,\(z\)个\(0\)链,组成所有环长都为\(3\)的倍数的方案数。注意到\(f(x,y,z)=(x+y+z)f(x,y,z-1)\)(可以接到剩下的任意......
  • Codeforces Round 929 (Div. 3)
    B.TurtleMath:FastThreeTask数学#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=1e5+10;inta[N];voidsolve(){ intn; cin>>n; intsum=0; map<int,int>mp; intmx=0; for(inti=1;i<=n;i++){ cin......
  • 11 .Codeforces Round 891 (Div. 3)E. Power of Points(推公式+前缀和优化)
    E.PowerofPoints题解参考#include<bits/stdc++.h>#defineintlonglong#definerep(i,a,b)for(inti=(a);i<=(b);++i)#definefep(i,a,b)for(inti=(a);i>=(b);--i)#define_for(i,a,b)for(inti=(a);i<(b);++i)#definepii......
  • CF-929(已更新:B-E)
    CF-929开学以来打得最烂的一场(⊙﹏⊙)B两种操作:删除一个元素、把一个元素的权值增加1。求使得序列元素和整除于3的最小操作次数。分析如果序列和sum模3的余数为0,答案为0,若为2,可以进行第二种操作,答案为1,但是若为1,答案就不一定为2,因为若能进行第一种操作删去一个模3为1的元素,......
  • Codeforces Round 929 (Div. 3) 题解(D-G)
    比赛链接:https://codeforces.com/contest/1933官解暂未放出。质量不错的一场D3。CF1933D.TurtleTenacity:ContinualMods题意将数组\(a_{1..n}\ge1\)重排,问是否能使\(((a_1\mathbin{\rmmod}a_2)\mathbin{\rmmod}a_3)\cdots\mathbin{\rmmod}a_n\ne0\)......
  • Codeforces Round 929 (Div. 3)
    CodeforcesRound929(Div.3)比赛链接A.TurtlePuzzle:RearrangeandNegate思路根据题意,很明显数组中所有元素的绝对值总和就是答案Code#include<bits/stdc++.h>usingnamespacestd;#defineall(x)x.begin()+1,x.end()#defineintlonglongvoidsolve(){......
  • Codeforces 441E Valera and Number
    首先看到\(\times2\)\(+1\)和最后答案的计算方式,能想到看成二进制来处理。考虑到\(\times2\)就是在最后加了一个\(0\)。不妨倒过来看,\(\times2\)就相当于舍弃了最低位。于是可以考虑\(\text{DP}\),\(f_{i,j}\)为考虑后面的\(i\)个操作,目前\(+\)的值为\(j\)的......