EOJ Monthly 2018.4
本次ECNUOJ的月赛因为学院里要大合唱…..所以就没有打,我们班唱完下场拿起手机看了看题,感觉前五题都不是很难啊(雾)。
A. ultmaster 的小迷妹们
这题可以转化为 ax−by=n a x − b y = n 是否有解,这么来说问题就很简单了,就不就是和 ax+by=c a x + b y = c 是否有解一个道理的吗,扩展欧几里得啊,那么解法就很简单了,判断 n n 是否是的整数倍就好了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
using namespace std;
typedef long long ll;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson root << 1
#define rson root << 1 | 1
int n;
int x,y;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>x>>y;
if(n%__gcd(x,y)==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
B. 代码查重
这题啊,STL简单应用.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson root << 1
#define rson root << 1 | 1
int n,m,k;
int a[100005];
int b[100005];
unordered_map< int,set<int> > mps;
set<int> s;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<m;i++)
cin>>b[i];
for(int i=1;i<=k;i++)
{
int x,y;
cin>>x>>y;
mps[x].insert(y);
}
if(n!=m)
{
cout<<"No"<<endl;
return 0;
}
else
{
int flag=0;
for(int i=0;i<n;i++)
{
if(a[i]==b[i]||mps[a[i]].find(b[i])!=mps[a[i]].end()||mps[b[i]].find(a[i])!=mps[b[i]].end())
continue;
else
{
flag=1;
break;
}
}
if(flag)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
}
暂时先写这两道水题,剩下几题会陆续补上,博主滚去写论文了,下周有三篇论文要交 (╯‵□′)╯︵┻━┻
E. 小迷妹在哪儿
传送门
这题有点简单啊,贪心的按照单位时间可得最大利益排个序然后背包一下就好了,怎么过的人这么少……
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson root << 1
#define rson root << 1 | 1
int n,T;
struct edge
{
double a,t;
}mi[100005];
bool cmp(edge x,edge y)
{
return x.a/x.t>y.a/y.t;
}
int dp[100005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>T;
for(int i=0;i<n;i++)
cin>>mi[i].a>>mi[i].t;
sort(mi,mi+n,cmp);
int Max=0;
for(int i=0;i<n;i++)
{
for(int j=T;j>=mi[i].t;j--)
{
dp[j]=max(dp[j],dp[j-(int)mi[i].t]+(T-j)*(int)mi[i].a);
Max=max(Max,dp[j]);
}
}
cout<<Max<<endl;
}