链接:​​https://codeforces.com/contest/670​



A - Holidays - [水]

AC代码:



#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin>>n;
int q=n/7, r=n%7;
int least=q*2;
int a,b;
if(r==0) a=b=0;
if(r==1) a=0, b=1;
if(2<=r && r<=5) a=0, b=2;
if(r==6) a=1, b=2;
printf("%d %d\n",least+a,least+b);
}


 



B - Game of Robots - [水]

AC代码:



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int n;
ll k;
int id[maxn];
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++) scanf("%d",&id[i]);

ll p;
for(p=1;p<=n;p++)
if((p-1)*p/2<k && k<=p*(p+1)/2) break;
k-=(p-1)*p/2;
cout<<id[k]<<endl;
}


 



C - Cinema - [离散化+排序]

AC代码:



#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int maxm=2e5+10;
int n,m;
int a[maxn],cnt[maxn+2*maxm];

vector<int> v;
inline int getID(int x){return lower_bound(v.begin(),v.end(),x)-v.begin()+1;}
inline int getVal(int id){return v.at(id-1);}

struct Mo{
int id;
int x,y;
}mo[maxm];
bool cmp(const Mo& a,const Mo& b)
{
if(cnt[a.x]==cnt[b.x]) return cnt[a.y]>cnt[b.y];
else return cnt[a.x]>cnt[b.x];
}

int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);

cin>>n;
for(int i=1;i<=n;i++) cin>>a[i], v.push_back(a[i]);
cin>>m;
for(int i=1;i<=m;i++) cin>>mo[i].x, v.push_back(mo[i].x);
for(int i=1;i<=m;i++) cin>>mo[i].y, v.push_back(mo[i].y);

sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for(int i=1;i<=n;i++)
{
a[i]=getID(a[i]);
cnt[a[i]]++;
}
for(int i=1;i<=m;i++)
{
mo[i].id=i;
mo[i].x=getID(mo[i].x);
mo[i].y=getID(mo[i].y);
}

sort(mo+1,mo+m+1,cmp);
cout<<mo[1].id<<endl;
}


 



D - Magic Powder - [二分]

题解:

二分能生产的饼干数目,对于一个饼干数目 $x$ 我们可以 $O(n)$ 判断出是否可行。

AC代码:



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e5+10;
int n;
ll k,a[maxn],b[maxn];

bool check(ll x)
{
ll need=0;
for(int i=1;i<=n;i++)
{
if(x*a[i]>b[i]) need+=x*a[i]-b[i];
if(need>k) return 0;
}
if(need>k) return 0;
else return 1;
}

int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++) scanf("%I64d",&a[i]);
for(int i=1;i<=n;i++) scanf("%I64d",&b[i]);

ll up=INF;
for(int i=1;i<=n;i++) up=min(up,(b[i]+k)/a[i]);

ll l=0, r=up;
while(l<r)
{
ll mid=(l+r+1LL)/2;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
}


 



E - Correct Bracket Sequence Editor - [线段树][链表][对顶栈]

1、​​线段树做法​​;

2、​​链表做法​​;

3、​​对顶栈做法​​。

 



​F - Restore a Number - [字符串]​

 ​