A. Ehab and another construction problem(暴力)
题目链接:https://codeforces.com/contest/1088/problem/A
题目大意:给一个n,从[1,n]中选择两个数,符合a*b>n&&a/b<n&&b可以被a整除。
如果能选择,随便输出一对符合要求的数,不能就输出-1
题解:日常水题,n属于[1,100]直接暴力。
AC:
int main()
{
std::ios::sync_with_stdio(false);
int x;
while(cin>>x)
{
int a=-1,b;
for(int i=1;i<=x;++i)
{//b
for(int j=1;j*i<=x&&j<x;++j)
{//a=b*j
if(i*j*i>x)
{
a=i*j;
b=i;
}
}
}
if(a==-1)
cout<<-1<<endl;
else
cout<<a<<" "<<b<<endl;
}
}
B. Ehab and subtraction(暴力)
题目链接:https://codeforces.com/contest/1088/problem/B
题目大意:给出一个数组,从这个数组中每次选择一个最小的元素,打印他,然后这个数组中所有的元素都减去这个数(0的话不减)。打印m次
思路:得到数组之后,从小到大排序,然后遍历这个数组,设置一个中间变量,每次+减去的值,在后面的时候再减去即可:
AC:
ll arr[MAXN];
int main()
{
std::ios::sync_with_stdio(false);
int n,k;
while(cin>>n>>k)
{
clean(arr,0);
for(int i=1;i<=n;++i)
cin>>arr[i];
sort(arr+1,arr+1+n);
ll res=0;
for(int i=1;i<=k;++i)
{
//cout<<res<<endl;
if(i>n)
cout<<"0 ";
else if(arr[i]-res<=0)
{
k++;
continue;
}
else
{
cout<<arr[i]-res<<" ";
res+=(arr[i]-res);
}
}
cout<<endl;
}
}
C. Ehab and a 2-operation task(思维)
题目链接:https://codeforces.com/contest/1088/problem/C
题目大意:给你一个n个元素的数组,经过k([0,n])次操作后,使得这个数组种的元素值严格递增,每次操作可以选择两个:
操作1:x位置元素之前的所有元素都+一个数;操作2:x之前的所有元素都对一个数取模
思路:因为可以操作n次,所以我的想法是直接暴力,遍历一遍之后,每个数都+一个数,然后对每个数取模,取模剩下的值为1,2,3,。。。即可;
AC:
int arr[MAXN];
int main()
{
std::ios::sync_with_stdio(false);
int n;
while(cin>>n)
{
clean(arr,0);
for(int i=1;i<=n;++i)
{
cin>>arr[i];
arr[i]+=1e5;
}
cout<<n+1<<endl<<"1 "<<n<<" 100000"<<endl;
for(int i=1;i<=n;++i)
cout<<"2 "<<i<<" "<<arr[i]-i<<endl;
}
}
D. Ehab and another another xor problem(交互问题,异或)
题目连接:https://codeforces.com/contest/1088/problem/D
题目大意:一开始有两个数a,b,我们要猜这两个数,每次询问“ ? c d ”,根据题上的条件返回结果,1,0,-1.然后最后猜出a和b
思路:好迷啊!第一次做这样的题,直觉上应该是一位一位的询问,但是根本不知道应该怎么写。。根本无从下手,于是翻看了题解,其实发现这道题还是挺有意思的,研究了一下午终于搞明白了。。就是一次询问两次,对于每一位,都进行比较。然后判断这个位应不应该有1||0,从高位先判(为了避免影响)。具体的解释我的代码中有的。可以看我的代码注释
AC:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<string>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define Pair pair<int,int>
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// 水印
//std::ios::sync_with_stdio(false);
// register
const int MAXN=2e5+10;
const int INF32=0x3f3f3f3f;
const ll INF64=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
const double PI=acos(-1.0);
int ask(int c,int d){
cout<<"? "<<c<<" "<<d<<endl;
int ans;
cin>>ans;
return ans;
}
int main(){
int a=0,b=0,big=ask(0,0);//big = a>b?1:-1 but if(a==b) big=0
for(int i=29;i>=0;--i){// 2^0~2^30
int f=ask(a^(1<<i),b),s=ask(a,b^(1<<i));//now if
if(f==s){// if there are same,
//1=1 or -1=-1 it mean that the big num has (1<<i)bit and the small num don't have
//because tow asks are both delete(add) (1<<i)bit,after,they are same.
//but if there are 1=1,it mean that a delete(1<<i)bit will bigger than b.
//-1=-1 is against.
if(big==1)//if a>b .the (1<<i)bit is in a.
a=a^(1<<i);
else//else is in b
b=b^(1<<i);
//than the (1<<i)bit was be consider.we don't should see the (1<<i)bit.
big=f;//if ans is 1=1,it mean a>b .else ans is -1=-1,it mean a<b.
}
else if(f==-1){//now the situation is -1 and 1,it mean that (1<<i)bit is both heve.
//because a^(1<<i) will smaller and b^(1<<i) will be smaller
//so the (1<<i)bit a and b both have 1.
a=a^(1<<i);
b=b^(1<<i);
}
//else is 1 and -1,it mean that the (1<<i)bit both don't have.
//becouse whichover ^(1<<i) it will be bigger
//cout<<"now I think a,b: "<<a<<" "<<b<<endl;
}
cout<<"! "<<a<<" "<<b<<endl;
}