ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510
时间限制:2s
空间限制:256MB
题目大意:
给定一个数字c
用 "max" "min" "+" "-" "" "/"对随机数 "?" 进行处理,使最后式子得到c的概率超过1/2
(所有数字均在0~255之间,"+" "-" "
"结果对256取模,"/" 向下取整)
样例:

解法:先使用多个"max"使得到的值趋近于255,然后相除得到1,然后相加到sqrt(c),再加到c
代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pi acos(-1.0)
#define mem0(a) memset(a,0,sizeof(a))
#define memf(b) memset(b,false,sizeof(b))
#define ll long long
#define eps 1e-10
#define inf 1e17
#define maxn 101010
string str="a=? max ?
b=a max a
c=b max b
d=c max c
e=d max d
f=e max e
g=f max f
h=g max g
i=h max h
j=i max i
k=j max j
l=k max k
m=l/l
";
int main()
{
	freopen("java2016.in","r",stdin);
	freopen("java2016.out","w",stdout);
	int n,i,j;
	cin>>n;
	if(n==0)
	{
		puts("?/?/?");
		return 0;
	}
	int nn=sqrt(n);
	string ans="n=m";
	for(int i=1;i<=nn-1;i++)
	{
		ans+="+m";
	}
	ans+="
";
	ans+="n*n";
	for(int i=nn*nn+1;i<=n;i++)
	{
		ans+="+m";
	}
	ans+="
";
	cout<<str<<ans;
	return 0;
}
原文地址:https://www.cnblogs.com/Destr/p/9740680.html