AtCoder Beginner Contest 174
cf这次要隔好久才能打,来打场abc放松下,结果赛中c做不出来了哈哈哈哈哈哈也是没谁了,赛后发现其实还是挺巧妙的??
A - Air Conditioner
判断是否小于30
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int main()
{
int n;
cin>>n;
if(n>=30)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
B - Distance
距离公式判断是否超过d
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int main()
{
int n;
double d;
scanf("%d%lf",&n,&d);
int ans=0;
while(n--)
{
double x,y;
scanf("%lf%lf",&x,&y);
if((x*x+y*y)<=d*d)
ans++;
}
cout<<ans<<endl;
}
C - Repsept
赛中居然卡了,主要看到最后那个样例人就傻了,完全忘记了取模这个东西,直接看代码吧,还挺直观的
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int main()
{
int n;
cin>>n;
int k=7;
int x=k%n;
int ans=1;
while(x)
{
if(ans>1000000)
break;
x=x*10+7;
x%=n;
ans++;
}
if(!x)
{
cout<<ans<<endl;
}
else
cout<<-1<<endl;
}
D - Alter Altar
要求没有W在R的左边,可以互换也可以直接变颜色,但显然互换在任何情况下都更优,所以直接双指针贪心的互换就行。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
char s[MAX_N];
int main()
{
int n;
cin>>n;
scanf("%s",s);
int i,j;
int len=strlen(s);
i=0;
j=len-1;
int ans=0;
for(i=0; i<j; i++)
{
if(s[i]=='W')
{
while(j>i&&s[j]=='W')
{
j--;
}
if(j!=i)
{
s[j]='W';
ans++;
}
}
}
cout<<ans<<endl;
}
E - Logs
n根棍子,总共可以切k次,要求切完后最长的那根木棍的最小值。
对于一个长len的木棍,假如我想切成最大不超过x长的每段,显然要切len/x-len%x==0.所以这题实际只要二分切出的最长段,然后通过总共要切多少次来判断就行,注意二分的过程中除数为0的情况,我赛中因为这re了一发。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int a[MAX_N];
int n,k;
int check(int x)
{
int ans=0;
int i;
for(i=1; i<=n; i++)
{
if(a[i]>x)
{
ans+=a[i]/x;
if(a[i]%x==0)
ans--;
}
if(ans>k)
return 1;
}
return 0;
}
int main()
{
cin>>n>>k;
int i;
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
int l=0;
int r=1000000000;
int mid=(l+r)/2;
while(l<=r)
{
if(mid==0)
break;
if(check(mid))
{
l=mid+1;
}
else
r=mid-1;
mid=(l+r)/2;
}
cout<<mid+1<<endl;
}