| 题目 | 难度 | 知识点 |
|---|---|---|
| A 小S按按钮 | ★ | 签到 |
| B 小R排数字 | ★ | 思维 |
| C 小T数星星 | ★ | 思维 |
| D 小A弹吉他 | ★★ | 数学/二分 |
wa麻了就不做了
小S按按钮
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t; cin>>t;
while(t--)
{
int x,y; cin>>x>>y;
if(x==0)cout<<max((y-1)*2+1,0)<<'\n';
else{
int ans=y/(1+x)*2;
y=y%(1+x);
if(y==1) ans++;
if(y>1) ans+=2;
cout<<ans<<'\n';
}
}
return 0;
}
小R排数字
只看后两位,因为1234=1200+34,1200必定是4的倍数。故只看后两位
#include<bits/stdc++.h>
using namespace std;
int a[15],st[15],flag;
string s;
int n;
int main(void)
{
int t; cin>>t;
while(t--)
{
cin>>s;
for(int i=0;i<s.size();i++) a[i]=s[i]-'0';
if(s.size()==1)
{
if(a[0]%4==0) cout<<"YES"<<'\n';
else cout<<"NO"<<'\n';
continue;
}
for(int i=0;i<s.size();i++)
{
for(int j=0;j<s.size();j++)
{
if(i==j) continue;
int temp=a[i]*10+a[j];
if(temp%4==0) flag=1;
}
}
if(flag) puts("YES");
else puts("NO");
flag=0;
}
return 0;
}
小T数星星
可以看出,想通数字再一块,但是必须个数为奇数,故奇数就一个,偶数拆成俩奇数
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t; cin>>t;
while(t--)
{
int n; cin>>n;
unordered_map<int,int>mp;
for(int i=0;i<n;i++)
{
int x; cin>>x;
mp[x]++;
}
int ans=0;
for(auto i=mp.begin();i!=mp.end();i++)
{
if(i->second&1) ans++;
else ans+=2;
}
cout<<ans<<'\n';
}
return 0;
}
小A弹吉他
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
bool check(LL mid,LL n)
{
LL temp=(mid+2)*(mid+1)*mid/6;
return temp<=n;
}
int main(void)
{
int t; cin>>t;
while(t--)
{
LL n; cin>>n;
LL l=0,r=2*1e6;
while(l<r)
{
LL mid=(l+r+1)/2;
if(check(mid,n)) l=mid;
else r=mid-1;
}
cout<<l+1<<endl;
}
return 0;
}