Educational Codeforces Round 167 (Rated for Div. 2)A. Catch the Coin
在角色和硬币移动同时进行时
1.若coin坐标y>=0时,角色让横坐标等于硬币横坐标的过程中,一定能把纵坐标的差变为0
2.y<0时,无论怎么操作都追不上硬币下降的位置
又因为角色先操作
所以y>=-1满足题意
代码如下
#include<bits/stdc++.h>
using namespace std;
int n,x,y;
int main()
{
cin>>n;
while(n--)
{
cin>>x>>y;
if(y>=-1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
Give string a and string b
Your task is to calculate the minimum possible length of the string that contains a as a substring and b as a subsequence.
设sting res 为 结果字符串
那么a就应该是不变的出现在res中,求出b中最大子串在a中为子序列的长度ll
答案就是size_a+size_b-l
代码如下
#include<bits/stdc++.h>
using namespace std;
string a,b;
int t,res;
void solve()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>t;
while(t--)
{
cin>>a>>b;
for(int i=0;i<b.size();i++)
{
int l=0;
for(int j=0;j<a.size();j++)
{
if(b[i+l]==a[j]) l++;
}
res=max(l,res);
}
cout<<a.size()+b.size()-res<<endl;
}
}
int main()
{
solve();
return 0;
}
The company's rating is the minimum of the ratings of the two movies. Your task is to calculate the maximum possible rating of the company.
贪心的使两个电影的评分尽可能的高且相近
1.若第i个人对两个评分不一样,取高的评分即可。
2.反之则考虑:
(1) 若ai=bi=0,则选择哪个电影都一样,所以不考虑
(2)若ai=1,则第i个人把评分给当前分低的
(3)若ai=-1,则第i个人把评分给当前分高的
代码如下
#include<bits/stdc++.h>
using namespace std;
const int N =2e5+10;
int a1,b1;
int t,n,res;
void solve()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>t;
while(t--)
{
cin>>n;
a1=b1=0;
vector<int> a(n+1),b(n+1);
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
cin>>b[i];
if(b[i]>a[i]) b1+=b[i];
if(b[i]<a[i]) a1+=a[i];
}
for(int i=1;i<=n;i++)
{
if(a[i]==b[i])
{
if(a[i]*(a1-b1)>0) b1+=b[i];
else a1+=a[i];
}
}
cout<<min(a1,b1)<<endl;
}
}
int main()
{
solve();
return 0;
}
What is the maximum total amount of experience you can earn by crafting and melting weapons?
可以发现最好的策略,一定是先利用锻造并融化后损失最小的来获取经验。这个贪心是可以证明的。那我们发现a的范围是1e6,那么如果C大于最大的ai,那我们可以选择一个最小损失的方案一直执行让他小于最大的ai,小于ai后,这个数据范围可以发现,我们可以利用dp来得到1e6范围的所有答案,那么这道题就完成了
代码如下
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int N =1e6+10;
int n,m;
void solve()
{
vector<int> a(N),b(N);
vector<int> d(1e6+10,1e7),dp(1e6+10);
cin>>n>>m;
int s=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
s=max(s,a[i]);
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
d[a[i]]=min(d[a[i]],a[i]-b[i]);
}
for(int i=1;i<=1e6;i++) d[i]=min(d[i],d[i-1]);
for(int i=1;i<=1e6;i++)
if(i-d[i]>=0) dp[i]=max(dp[i],dp[i-d[i]]+1);
LL res=0;
for(int i=1;i<=m;i++)
{
int c;
cin>>c;
if(c>s)
{
int r=(c-s)/d[s]+1;
c-=r*d[s];
res+=r;
}
res+=dp[c];
}
cout<<res*2<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}