标签:algorithm open bitset 位置 -- highlight 另一个 class 水题
比赛过程:
A是个水题,花了3分钟A了
没了,后面都没过
涨分15
==================================
A
给你n个数,你可以任意重新排列这些数
求最多有几个数能严格大于这个位置原来的数
n<=105
排序以后直接做...
B
给你三个数A,B,C
求有多少个整数的(a,b,c)使得A*B*C的立方体可以被切成若干个a*b*c的立方体
要求a<=b<=c
多测,100000组数据,1<=A,B,C<=100000
C
给你一个n,让你猜x和y
x,y都是[1,n]以内的整数
每次你猜一个x,y
对面会回答:
x小了
y小了
x大了或者y大了
不会说谎,但是有多个回答可能会随机回答
DE
没看
==================================================
C题赛后过了
用类似于二分的办法
针对了一下数据
应该是错的
每次把看到1,2就修改l
看到3就修改r,两个r都修改,直到出现一维r>l
这时候另一个r显然就是真实的范围,同时把这个r恢复到最大值(n或者上一次矛盾推导出的r)
复杂度O(log^2),会炸
我每次修改完l以后会直接把l拉到上限再做一次询问,这样做针对了下数据,过了
代码:
A
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
#ifdef absi2011
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n;
scanf("%d",&n);
int i;
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int cnt=0;
a[n]=-1;
int ans=0;
for (i=0;i<n;)
{
int j;
for (j=i;a[j]==a[i];j++)
{
if (cnt>0)
{
cnt--;
ans++;
}
}
cnt+=(j-i);
i=j;
}
printf("%d\n",ans);
return 0;
}
C
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int query(long long x,long long y)
{
cout<<x<<" "<<y<<"\n";
fflush(stdout);
int n;
if (cin>>n)
{
return n;
}
else
{
exit(-1);
}
}
int main()
{
#ifdef absi2011
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#endif
long long n;
cin>>n;
long long l1=1,l2=1,r1=n,r2=n;
for (;;)
{
long long t_l1=l1,t_l2=l2,t_r1=r1,t_r2=r2;
for (;;)
{
long long mid1=(l1+r1)/2;
long long mid2=(l2+r2)/2;
int ans=query(mid1,mid2);
if (ans==0)
{
return 0;
}
else if (ans==1)
{
l1=mid1+1;
t_l1=mid1+1;
int ans=query(r1,mid2);
if (ans==1)
{
l1=r1+1;
}
else if (ans==0)
{
return 0;
}
else if (ans==2)
{
l2=mid2+1;
t_l2=mid2+1;
}
}
else if (ans==2)
{
l2=mid2+1;
t_l2=mid2+1;
int ans=query(mid1,r2);
if (ans==2)
{
l2=r2+1;
}
else if (ans==0)
{
return 0;
}
else if (ans==1)
{
l1=mid1+1;
t_l1=mid1+1;
}
}
else
{
r1=mid1-1;
r2=mid2-1;
}
if (r1<l1)
{
t_r2=r2;
break;
}
if (r2<l2)
{
t_r1=r1;
break;
}
}
l1=t_l1;
l2=t_l2;
r1=t_r1;
r2=t_r2;
if ((l1>r1)||(l2>r2)) return 1;
/*
if (l1==r1)
{
for (;;)
{
int mid=(l2+r2)/2;
int ans=query(l1,mid);
if (ans==0)
{
return 0;
}
else if (ans==2)
{
l2=mid+1;
}
else if (ans==3)
{
r2=mid-1;
}
}
}
if (l2==r2)
{
for (;;)
{
int mid=(l1+r1)/2;
int ans=query(mid,l2);
if (ans==0)
{
return 0;
}
else if (ans==1)
{
l1=mid+1;
}
else if (ans==3)
{
r1=mid-1;
}
}
}
*/
}
return 0;
}
标签:algorithm open bitset 位置 -- highlight 另一个 class 水题
原文地址:https://www.cnblogs.com/absi2011/p/9315198.html