AtCoder Beginner Contest 297 C~E
c:
You are given H strings S1,S2,…,SH, each of length W, consisting of . and T.Takahashi may perform the following operation any number of times (possibly zero):- Choose integers satisfying 1≤i≤H and 1≤j≤W−1 such that the j-th and (j+1)-th characters of Si are both T. Replace the j-th character of Si with P, and (j+1)-th with C.He tries to maximize the number of times he performs the operation. Find possible resulting S1,S2,…,SH.
题意:就是判断连续的两个是不是都是T
代码:
void solve()
{
std::cin >> n >> m;
for(int i = 1;i <= n;i ++)
{
std::cin >> s[i];
}
for(int i = 1;i <= n;i ++)
{
for(int j = 1;j < m;j ++)
{
if(s[i][j-1] == 'T'&&s[i][j] == 'T')
{
s[i][j-1] = 'P';
s[i][j] = 'C';
}
}
}
for(int i = 1;i <= n;i ++)
std::cout << s[i] << '\n';
}
D:
You are given positive integers A and B. You will repeat the following operation until A=B: compare A and B to perform one of the following two if A>B, replace A with A−B; if AHow many times will you repeat it until A=B? It is guaranteed that a finite repetition makes A=B.
题意:给你两个数,让你判断需要多少次变化可以让这两个数相等
思路:这个看上去和__gcd的原理有点像,首先我们发现大的数会依次相减直到小于或者等于另一个数所以我们可以对他取模得到的就是下一次要改变的数
代码:
void solve()
{
int ans = 0;
std::cin >> n >> m;
if(n == m)
{
std::cout << 0 << '\n';
return ;
while(n!=m)
{
int w = abs(n-m);
if(n > m)
{
ans += n/m;
if(n%m==0)
n = m;
else
n = n%m;
}
else
{
ans += m/n;
if(m%n==0)
m = n;
else
m = m%n;
}
}
std::cout << ans-1 << '\n';
}
E:
In AtCoder Kingdom, N kinds of takoyakis (ball-shaped Japanese food) are sold. A takoyaki of the i-th kind is sold for Ai yen. Takahashi will buy at least one takoyaki in total. He is allowed to buy multiple takoyakis of the same kind. Find the K-th lowest price that Takahashi may pay. Here, if there are multiple sets of takoyakis that cost the same price, the price is counted only once.
题意:给你n,m两个数,其中n个数可以互相组成其他的数,或者自己组成其他的数,求第m个数是多少
思路,我们让最小的数每次加这n个数再把最小的删除就可以了
代码:
void solve()
{
std::cin >> n >> m;
for(int i = 1;i <= n;i ++)
{
std::cin >> a[i];
}
std::set<int>se;
se.insert(0);
while(m--)
{
int x = *se.begin();
se.erase(x);
for(int i = 1;i <= n;i ++)
{
se.insert(x+a[i]);
}
}
std::cout <<*se.begin() << '\n';
}