AtCoder Beginner Contest 209

A - Counting 

水题。

题意:给你a,b两个数问你有多少个数≥a且≤b;

代码:

#include<bits/stdc++.h>
#define ll long long
const int maxn=1e5+5;
using namespace std;
void solve()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
	{
		cout<<0;
	}
	else cout<<b-a+1;
}
int main()
{
	ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	solve();
	return 0;
}

https://atcoder.jp/contests/abc209/tasks/abc209_b

B - Can you buy them all? 

水题。

题意:给你n个物品其他们的价格位ai元,再给你x元。你第偶数件物品的价格可以减一块钱。请问你可以把这n个物品都买完嘛?

思路:先计算这些物品的总价格,再减去优惠:n/2元,最后与x比较就可以了。

代码:

#include<bits/stdc++.h>
const int maxn=1e5+5;
using namespace std;
int f[10000],n,x,ans;
void sovle()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>f[i];
		ans+=f[i];
	}
	ans-=(n)/2;
	if(ans<=x)cout<<"Yes";
	else cout<<"No";
}
int main()
{
	ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	sovle();
	return 0;
}

https://atcoder.jp/contests/abc209/tasks/abc209_c

C - Not Equal

题意:给你一个长度为n的数组c,让你求有多少种数组a,使得ai<=ci且ai!=aj(a数组里没有一个数是相同的)。

思路:先对c数组从小到大排序,对与ci可以存的数字个数位ci-i+1;ans=(ans*(ci-i+1))%mod

代码:

#include<bits/stdc++.h>
#define ll long long
#define hh 0x3f3f3f3f
const int maxn=2e5+5;
using namespace std;
ll mod=1e9+7;
inline int read()
{
	ll s=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=(s<<3)+(s<<1)+c-'0';c=getchar();}
	return s*f;
}
int n;
ll f[maxn],ans=1;
void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>f[i];
	sort(f+1,f+1+n);
	for(int i=1;i<=n;i++)
	{
		ans=(ans*(f[i]-i+1))%mod;	
	}	
	cout<<ans;
}
int main()
{
	ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	solve();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值