A - Air Conditioner
题意&&思路:
if (大于30就)输出yes。
else 输出no。
AC
#include <iostream>
using namespace std;
int main()
{
int x;
cin>>x;
if(x>=30)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
B - Distance
题意:
给一个圆,判断有多少个点在园内。
思路:
距离公式时,最好不要开方。
AC
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
ll n,d;
cin>>n>>d;
d*=d;
ll ans=0,x,y;
for(ll i=1; i<=n; i++){
cin>>x>>y;
if(x*x+y*y<=d)ans++;
}
cout<<ans<<endl;
return 0;
}
C - Repsept(同余)
题意:
给你一个因子k。
要你判断它是哪个重7数
的因子。
思路:
同余。
假设重7数
为x(n)。(表示有n个7)
- 那么就要找到一个x(n)%k==0;
- 这里就可以转换成同余了。x(n)=( x(n-1)%k *(10%k))%k+7%k。
- 假如x(n)%k==0,那么就是
ans=n
。 - 所以可以开始暴力枚举了。
AC
#include <iostream>
using namespace std;
const int maxn=1e6+10;
int main()
{
int k;cin>>k;
int tmp=0;
int ans=-1;
for(int i=1; i<=maxn; i++){
tmp=((tmp%k)*(10%k)%k+7%k)%k;
if(tmp%k==0){
ans=i;
break;
}
}
cout<<ans<<endl;
return 0;
}
D - Alter Altar(简单讨论)
题意:
- 给你n个stones的字符串。
- 有两种stones,red&&white。
- 对于
wr
不好,要想办法,最少的操作消除。 - operation1:改变 s w a p ( I , j ) swap(I,j) swap(I,j)
- operation2: 改变一个石头的颜色。
思路(英语官方题解还没出):
我写了三个判断。
- 把所有的red移到左边,white移到右边,的操作数ans1.
- 当出现
wr
时,选择变w为r。(ans2) - 当出现
wr
时,选择变r为w。 (ans3) - 取min。
AC
#include <iostream>
#include <string>
#include <algorithm>
#define all(a) a.begin(),a.end()
using namespace std;
const int maxn=2e5+10;
int main()
{
int n;cin>>n;
string s;cin>>s;
string b=s;
sort(all(b));
int ans1=0,ans2=0,ans3=0;
for(int i=0; i<n; i++){
if(s[i]!=b[i])ans1++;
}
ans1/=2;
int tmp=0,flag=0;
for(int i=0; i<n; i++){
if(s[i]=='W')flag=1,tmp++;
else {
if(flag)ans2+=tmp;
tmp=flag=0;
}
}
tmp=flag=0;
for(int i=n-1; i>=0; i--){
if(s[i]=='R')flag=1,tmp++;
else {
if(flag)ans3+=tmp;
flag=tmp=0;
}
}
cout<<min(ans1,min(ans2,ans3))<<endl;
return 0;
}
E - Logs(二分答案)
题意:
有n个logs。最多切k次。
问:
求 :切完后,剩下的log中,最长的最小可能。
思路:
- 二分答案。
- 之后check答案。
反思:
- 下届没取好,10wa.血与泪的教训。qwq。
- 本题因为rounding答案和a【i】>=1。所以无论怎么切,
ans肯定大于0. 那么l肯定要从1开始
AC
#include <iostream>
#define exp 1e-6
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int n,k;
bool check(int x){
int cnt=0;
for(int i=1; i<=n; i++){
if(a[i]>x&&x){
cnt+=a[i]/x;
}
if(cnt>k)return false;
}
return true;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;
int l=1, r=0,ans=0;///下界没选好,wa10发qwq。。。
for(int i=1; i<=n; i++)cin>>a[i],r=max(r,a[i]);
ans=r;
if(k==0||r==1){
cout<<ans<<endl;
return 0;
}
while(l<=r){
int mid=(l+r)>>1;
// cout<<mid<<endl;
if(check(mid))ans=mid,r=mid-1;
else l=mid+1;
}
cout<<ans<<endl;
return 0;
}