A Vlad and the Best of Five
签到题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=102;
void solve()
{
string s;
int a=0,b=0;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='A') a++;
else b++;
}
if(a>b) cout<<"A"<<endl;
else cout<<"B"<<endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--)
solve();
}
B Vlad and Shapes
找到一个左右都为“0”的“1”,这个“1”如果如果存在,它就是三角形的顶点。
这样就可以判断他是个三角形。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
int n;
void solve()
{
cin>>n;
char f[110][110]{0};
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>f[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(f[i][j]=='1'&&f[i][j-1]=='0'&&f[i][j+1]=='0')
{
cout<<"TRIANGLE"<<endl;
return;
}
}
}
cout<<"SQUARE"<<endl;
return;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
}
C. Vlad and a Sum of Sum of Digits
用数组存储前缀和,就可以防止重复计算
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=2e5+10;
ll F[N];
int n;
int t;
int f(int x) {
string s = to_string(x);
int sum=0;
for (int i=0;i<s.size();i++) {
int y=s[i]-'0';
sum+=y;
}
return sum;
}
void solve()
{
for(int i=1;i<=2e5+10;i++)
{
F[i]=F[i-1]+f(i);
}
cin>>t;
while(t--)
{
cin>>n;
cout<<F[n]<<endl;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
}
D. Vlad and Division
题目要求每一位都不同的两个数才能放进一个组,所以一个组最多两个数。
题目又说Ai<2^31,所以要求是两个数的31个位都是不同的。
样例中有这么一组数据

![]()
0和2147483647一组,所以它们31个位都是不同的,又因为0的每个位都是0,所以2147483647就是每个位都是1的情况,即2^31.
这样就简单了,假如a是一个数字,与它同组的数b就等于a^2147483647
每输入一个数,先看mp中它对应的那个数在不在,在的话就抵消,组数+1;不在的话,就添加键值。
最后统计时,单独遗留一个键的就自己一组,组数+1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=2e5+10;
void solve()
{
map<ll,int>mp;
int n;
cin>>n;
ll m;
ll cnt=0;
ll C=2147483647;
while(n--)
{
cin>>m;
if(mp[m^C])
{
mp[m^C]--;
cnt++;
}
else mp[m]++;
}
for(auto it:mp)
{
cnt+=it.second;
}
cout<<cnt<<endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while(T--) solve();
}
E. Vlad and an Odd Ordering
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int dx[8]={-1, 0, 1, 0, 1, -1, 1, -1};
const int dy[8]={0, 1, 0, -1, -1, 1, 1, -1};
const int N=5e4+10;
void solve()
{
ll n,k;
cin>>n>>k;
ll cnt=0;
while(k>(n+1)/2)
{
ll m=(n+1)/2;
k-=m;
n/=2;
cnt++;
}
cout<<((2*k-1)<<cnt)<<endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while(T--) solve();
}
文章介绍了五道编程题目,涉及C++语言中的字符处理、形状判断(如三角形和正方形)、前缀和计算、数字特征(每位不同)以及奇数序列生成,展示了在IT技术中解决实际问题的方法。

1185

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



