Codeforces Round #673 (Div. 2)
[Codeforces Round #673 (Div. 2) ]
题目链接#
A. Copy-paste
思路:
贪心的策略。每次只加上最小的就可以了
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;
ll a[1010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
while(t--)
{
ll ans=0,n,k;
cin>>n>>k;
for(ll i=0; i<n; i++)
cin>>a[i];
sort(a,a+n);
for(ll i=1; i<n; i++)
{
ans+=(k-a[i])/a[0];
}
cout<<ans<<"\n";
}
return 0;
}
B. Two Arrays
思路:
晚上的思路是用hashmap来实现…但做着做着到了12点,做不下去了就耻辱得下机。。
看群里也有人在讨论这道题..各种想法的都有,结果大家都想多了。这不就是一道贪心题/doge
以\(T/2\)作为界限,小的涂白(1),大的涂黑(0)。边读入边做就行了。
《论审题的重要性》
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;
const int max_n=1e5+5;
ll a[max_n];// c whilte d black
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
while(t--)
{
memset(a,0,sizeof(a));
ll n,k,cnt=0,x;
cin>>n>>k;
for(ll i=0; i<n; i++)
{
cin>>x;
if (x*2==k)
a[i]=(cnt++)%2;
else if (x*2<k)
a[i]=1;
}
for(ll i=0; i<n; i++)
cout<<a[i]<<' ';
cout<<"\n";
}
return 0;
}
下面的题目等div3结束抽空补了
版权声明:本文为william4s原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。