比赛链接:https://ac.nowcoder.com/acm/contest/3003
其他比赛题解:
【题解】2020牛客寒假算法基础集训营1
【题解】2020牛客寒假算法基础集训营3
【题解】2020牛客寒假算法基础集训营4
【题解】2020牛客寒假算法基础集训营5
原题链接:https://ac.nowcoder.com/acm/contest/3003/A
Code:
#include
using namespace std;
typedef long long ll;
int main(){
ll a,b,c; cin>>a>>b>>c;
ll x,y,z; cin>>x>>y>>z;
cout<<min(a,y)+min(b,z)+min(c,x)<<endl;
return 0;
}
原题链接:https://ac.nowcoder.com/acm/contest/3003/B
Code:
#include
#include
using namespace std;
int main(){
int n; cin>>n;
string str; cin>>str;
int sum1=0,sum2=0;
for(int i=0;i<str.length();i++){
if(str[i]=='1') sum1++;
if(str[i]=='6') sum2++;
}
cout<<max(min(sum1,sum2-1),0)<<endl;
return 0;
}
原题链接:https://ac.nowcoder.com/acm/contest/3003/C
Code:
#include
using namespace std;
typedef long long ll;
const int N=2e3+10;
const ll mod=1e9+7;
ll dp[N][N],p[N];
int main(){
int n; cin>>n;
for(int i=1;i<=n;i++)
cin>>p[i];
dp[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<=i;j++)
dp[i][j]=(dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i])%mod;
for(int i=0;i<=n;i++){
if(dp[n][i]<0) cout<<dp[n][i]+mod<<' ';
else cout<<dp[n][i]<<' ';
}
cout<<endl;
return 0;
}
原题链接:https://ac.nowcoder.com/acm/contest/3003/D
Code:
#include
#include
#include
using namespace std;
typedef long long ll;
struct node{
int x,y;
}arr[1000];
bool cmp(node a,node b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int main(){
int n; cin>>n;
for(int i=1;i<=n;i++)
cin>>arr[i].x>>arr[i].y;
sort(arr+1,arr+1+n,cmp);
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
for(int k=j+1;k<=n;k++){
int a = (arr[i].x-arr[j].x)*(arr[i].x-arr[j].x)+(arr[i].y-arr[j].y)*(arr[i].y-arr[j].y);
int b = (arr[j].x-arr[k].x)*(arr[j].x-arr[k].x)+(arr[j].y-arr[k].y)*(arr[j].y-arr[k].y);
int c = (arr[i].x-arr[k].x)*(arr[i].x-arr[k].x)+(arr[i].y-arr[k].y)*(arr[i].y-arr[k].y);
if(c<a) swap(c,a);
if(c<b) swap(c,b);
if(sqrt(a)+sqrt(b)>sqrt(c) && a+b<c)
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}
原题链接:https://ac.nowcoder.com/acm/contest/3003/E
Code:
#include
#include
using namespace std;
typedef long long ll;
const int N=4e7;
ll a[N+10];
int main(){
int n; cin>>n;
int x;
for(int i=1;;i++){
if(i*i<=N)
a[i]=i*i;
else{
x=i-1;
break;
}
}
ll ans=0;
for(int i=1;i<=x;i++){
if(a[i]>n) break;
for(int j=1;j*j<=a[i];j++){
if(a[i]%j==0){
if(j*j==a[i]) ans++;
else ans+=2;
}
}
}
cout<<ans<<endl;
return 0;
}
原题链接:https://ac.nowcoder.com/acm/contest/3003/F
Code:
#include
#include
using namespace std;
const int N=2e5;
struct node{
int a,b,num;
}arr[N];
bool cmp(node x,node y){
return x.a+x.b>y.a+y.b;
}
int main(){
int n; cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i].a;
arr[i].num=i;
}
for(int i=1;i<=n;i++)
cin>>arr[i].b;
sort(arr+1,arr+1+n,cmp);
for(int i=1;i<=n;i++)
if(i%2)
cout<<arr[i].num<<' ';
cout<<endl;
for(int i=1;i<=n;i++)
if(i%2==0)
cout<<arr[i].num<<' ';
cout<<endl;
return 0;
}
原题链接:https://ac.nowcoder.com/acm/contest/3003/G
Code:
#include
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll q_pow(ll a,ll b,ll mod){
ll ans=1,res=a;
while(b){
if(b&1) ans=ans*res%mod;
res=res*res%mod;
b>>=1;
}
return ans%mod;
}
int main(){
int t; cin>>t;
while(t--){
ll a,b,c,d,e,f,g; cin>>a>>b>>c>>d>>e>>f>>g;
if(q_pow(a,d,mod)+q_pow(b,e,mod)+q_pow(c,f,mod)==g)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}