序列变换
Accepts: 695
Submissions: 3322
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
魔法因子
Accepts: 215
Submissions: 1208
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
(h*power+l+mid)*a=(l*power+h+mid)*b
可推得:mid=((h*power+l)*a-(l*power+h)*b)/(a-b);
所以可以枚举h,l然后求mid,注意mid的最低位一定是0,因为留出最低位加l或者h
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=20;
double x;
vector<LL> ans;
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%lf",&x);
LL a=LL(x*1e6+0.1);
LL b=1e6;
ans.clear();
for(int len=2;len<=10;len++)
{
LL power=1;
for(int j=1;j<len;j++)power*=10;
for(int h=1;h<=9;h++)
{
for(int l=0;l<=9;l++)
{
LL offset=(power*l+h)*b-(power*h+l)*a;
if(offset%(10*(a-b))==0)
{
LL mid=offset/10/(a-b),tmpmid=mid;
if(tmpmid<0)continue;
int cnt=0;
while(tmpmid)
cnt++,tmpmid/=10;
if(cnt<=len-2)ans.push_back(power*h+mid*10+l);
}
}
}
}
printf("Case #%d:\n",cas++);
printf("%d\n",ans.size());
int len=ans.size();
for(int i=0;i<len;i++)
{
printf("%I64d",ans[i]);
if(i!=len-1)printf(" ");
else printf("\n");
}
}
return 0;
}
追星族
Accepts: 21
Submissions: 122
Time Limit: 6000/3000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
下面的代码是比赛时过了的
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
#include <complex>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef vector<ll> VL;
const ll mod=1000000007;
const int N=50100;
int _,n,__;
ll x[N],y[N],t[N],inf=1ll<<60;
PLL p[N],q[N];
ll solve(pair<ll,ll> *p) {
sort(p,p+n);
ll ret=0;
ll l=p[0].se,r=p[0].se;
rep(i,1,n) {
l-=(p[i].fi-p[i-1].fi);
r+=(p[i].fi-p[i-1].fi);
l=max(l,p[i].se); r=min(r,p[i].se);
ret=max(ret,l-r);
}
return ret;
}
int main() {
for (scanf("%d",&_);_;_--) {
scanf("%d",&n);
rep(i,0,n) scanf("%I64d%I64d%I64d",x+i,y+i,t+i);
rep(i,0,n) p[i]=mp(t[i],x[i]+y[i]);
rep(i,0,n) q[i]=mp(t[i],x[i]-y[i]);
ll ret=max(solve(p),solve(q));
printf("Case #%d:\n",++__);
if (ret<0) puts("0/1");
else {
if (ret%2==0) printf("%I64d/1\n",ret/2);
else printf("%I64d/2\n",ret);
}
}
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define Max(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((b) & FASTBUFFER | (a) & ~FASTBUFFER))
#define Min(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((a) & FASTBUFFER | (b) & ~FASTBUFFER))
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)
#define OO 2147483647
#define priority_queue PQ
using namespace std;
int FASTBUFFER;
int test, tt, n;
const int N = 50005;
struct Point {
long long x, y, t;
friend bool operator < (const Point &a, const Point &b) {
return a.t < b.t;
}
void read() {
int xx, yy;
scanf("%d %d %I64d", &xx, &yy, &t);
t <<= 1;
x = xx + yy;
y = xx - yy;
x <<= 1;
y <<= 1;
}
} p[N];
struct rec {
long long x1, y1, x2, y2;
void expand(long long d) {
x1 -= d;
y1 -= d;
x2 += d;
y2 += d;
}
};
struct rec intersect(const rec &a, const rec &b) {
rec ret;
ret.x1 = max(a.x1, b.x1);
ret.x2 = min(a.x2, b.x2);
ret.y1 = max(a.y1, b.y1);
ret.y2 = min(a.y2, b.y2);
return ret;
}
int ok(long long ans) {
rec now;
now.x1 = now.x2 = p[1].x;
now.y1 = now.y2 = p[1].y;
now.expand(ans);
for (int i = 2; i <= n; i++) {
now.expand(p[i].t - p[i - 1].t);
rec temp;
temp.x1 = temp.x2 = p[i].x;
temp.y1 = temp.y2 = p[i].y;
temp.expand(ans);
now = intersect(now, temp);
if (now.x1 > now.x2 || now.y1 > now.y2) {
return 0;
}
}
return 1;
}
void work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
p[i].read();
}
sort(p + 1, p + n + 1);
long long l = 0, r = 10000000000LL;
while (l < r) {
long long mid = (l + r) >> 1;
if (ok(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
if (!(l & 1)) {
printf("%I64d/1\n", l / 2);
} else {
printf("%I64d/2\n", l);
}
}
int main() {
scanf("%d", &test);
while (test--) {
printf("Case #%d:\n", ++tt);
work();
}
return 0;
}