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

被折叠的 条评论
为什么被折叠?



