Codeforces Round #739 (Div. 3)
A
#include <bits/stdc++.h>
using namespace std;
signed main()
{
int t;
cin>>t;
while (t--)
{
int k,cou = 0;
cin>>k;
for (int i=1;;i++)
{
if (i%3==0||i%10==3) ;
else cou++;
if (cou==k)
{
cout<<i<<endl;
break;
}
}
}
}
B
#include <bits/stdc++.h>
using namespace std;
signed main()
{
int t;
cin>>t;
while (t--)
{
int a,b,c;
cin>>a>>b>>c;
int cou = max(a,b)-min(a,b);
cou*=2;
// cout<<cou<<endl;
if (c>cou||abs(a-b)==1||max(a,b)>cou) cout<<-1<<endl;
else
{
if (c-cou/2<1) cout<<c+cou/2<<endl;
else cout<<c-cou/2<<endl;
}
}
}
C
#include <bits/stdc++.h>
using namespace std;
signed main()
{
int t;
cin>>t;
while (t--)
{
int k,cou=1,g;
cin>>k;
for (int i=1;;i++)
{
cou = i*i;
if (cou>=k)
{
g = i;
break;
}
}
int h = g*g-(g-1)*(g-1);
int hh = k-(g-1)*(g-1);
// cout<<h<<" "<<hh<<endl;
if (hh<=h/2)
{
cout<<hh<<" "<<g<<endl;
}
else
{
cout<<g<<" "<<h-hh+1<<endl;
}
}
}
E
#include <bits/stdc++.h>
using namespace std;
signed main()
{
int t;
cin >> t;
while (t--)
{
string str, s;
cin >> str;
// cout<<str<<endl;
int len = str.length();
int ch[101] = {0};
int op[101] = {0};
for (int i = len - 1; ~i; i--)
{
// cout<<str[i]<<" ";
int k = str[i]-'a';
// cout<<k<<" ";
if (ch[k] == 0)
{
s += str[i];
ch[k]++;
}
else ch[k]++;
}
reverse(s.begin(),s.end());
int len1 = s.length();
for (int i=0;i<len1;i++)
{
int k = s[i]-'a';
// cout<<k<<" "<<len1-i<<" ";
op[k] = ch[k]/(i+1);
// cout<<op[k]<<" ";
}
string ss;
for (int i=0;i<len;i++)
{
char k = str[i]-'a';
if (op[k]==0) break;
else
{
ss+=str[i];
op[k]--;
}
}
string tt = ss;
int ha[101]={0};
for (int i=0;i<len1;i++)
{
int k = s[i]-'a';
ha[k] = -1;
for (int j=0;j<ss.length();++j)
{
int u = ss[j]-'a';
if (ha[u]==0) tt+=ss[j];
}
}
// cout<<tt<<endl;
bool flag = true;
for (int i=0;i<50;i++)
{
if (op[i]!=0)
{
flag = false;
break;
}
}
if (flag&&tt==str)
{
cout<<ss<<" "<<s<<endl;
}
else cout<<-1<<endl;
}
}