[考试总结]noip模拟18
发现之前咕掉了这个考试的总结。
今天就把它给补上。
这也是一个炸裂的一场
开局以为 \(T1\) 可做,然而事实证明我又错了。。。
莽了一个随机化上去,轻松过了所有样例。。。
以为稳了
然而挂掉了。。。
\(25pts\) 不如暴力
然后感觉 \(T2\) 并不是很可调,所以就打了一个只有俩方程式的部分分数。。。
然后还挂了。
其实一眼就能看出来是高斯消元。然后错误的认为大多数人调不出来。
然而到最后这个题目的得分最高。。。。
无话可说。。
\(T3\) 也是一个玄学题目。
然而特殊性质全部打挂。。。
只留下了 \(20pts\) 的暴力分数。。。
导弹袭击:
简单凸包
我们首先简化一下题目所给的信息。
其实就是找到
\[\frac {A}{a_i} + \frac{B}{b_i}
\]
这个式子的最值,我们经过一顿乱化。
然后可以将这个式子转化为一个斜率式
将 \((\frac {1}{a_i},\frac {1}{b_i})\) 看作坐标系上面的点
之后用单调栈维护这个函数的凸包就行了
#include<bits/stdc++.h>
using std::cout; using std::endl;
#define debug cout<<"debug"<<endl
#define double long double
#define R register int
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
int eat1; FILE *eat2; char buf[1<<20],*p1 = buf,*p2 = buf;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
template<class type>inline type get()
{
type s = 0,f = 1; register char ch = gc();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io; static const int maxn = 1e6+10,inf = 0x7f7f7f7f;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
typedef long long ll;
namespace xin
{
class xin_data
{
public:
int x,y,id;
friend bool operator < (xin_data x,xin_data y)
{return (x.x == y.x) ? x.y > y.y : x.x > y.x;}
}d[maxn];
double xie[maxn];
inline double k(xin_data i,xin_data j)
{return (double)(1.0 * i.x * j.x * (j.y - i.y)) / (double)(1.0 *i.y * j.y * (j.x - i.x));}
int n;
int q[maxn],top = 0;
int nxt[maxn];
bool vis[maxn];
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get<signed>();
int maxx = 0,maxy = 0;
try(i,1,n)
{
d[i].x = get<signed>(); d[i].y = get<signed>(); d[i].id = i;
if(maxy < d[i].y or (maxy == d[i].y and maxx < d[i].x)) maxx = d[i].x,maxy = d[i].y;
}
std::sort(d+1,d+n+1);
// for(int i=1;i<=n;++i) cout<<p[i].x<<' '<<p[i].y<<' '<<p[i].id<<endl;
q[++top] = 1;
for(register int i=2;i<=n and maxx<=d[i].x;++i)
{
if(d[q[top]].x==d[i].x)
{
if(d[q[top]].y==d[i].y)
nxt[d[i].id]=nxt[d[q[top]].id],nxt[d[q[top]].id]=d[i].id;//,q[++t] = i,k[t]=k[t-1];
}
else
{
while(top > 1 and xie[top] > k(d[q[top]],d[i]))
top--;
q[++top]=i;xie[top] = k(d[q[top-1]],d[i]);
}
}
for(;top;--top) for(register int i=d[q[top]].id;i;i=nxt[i])
vis[i]=1;
// for(;t;--t) f[q[t].id] = 1;
for(register int i=1;i<=n;++i)
if(vis[i])printf("%d ",i);
return 0;
}
}
signed main() {return xin::main();}
炼金术士的疑惑:
就是朴实无华的高斯消元。
只不过处理那些字符串读入的时候细节比较多。
没什么好说的
#include<bits/stdc++.h>
using std::cout; using std::endl;
#define debug cout<<"debug"<<endl
namespace xin_io
{
#define scanf eat1 = scanf
#define freopen eat2 = freopen
int eat1; FILE *eat2;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
}
#define double long double
using namespace xin_io; static const int maxn = 1e3+10,inf = 0x7f7f7f7f;const double eps = 1e-15,pan = 1.7;
const double ki = 2.116,ki2 = 5.897;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
typedef long long ll;
namespace xin
{
double a[maxn][maxn];
int n,ok = 0;
std::string m[maxn]; int tot;
double ans[maxn],ret = 0.0;
inline bool equal(double x,double y) {return fabs(x - y) <= eps;}
inline void gss()
{
for(register int i=1;i<=n;++i)
{
int k = i;
double t;
for(register int j=i+1;j<=n;++j)
if(fabs(a[k][i]) < fabs(a[j][i]))
k = j;
if(k != i)
for(register int j=1;j<=n+1;++j)
t = a[k][j],a[k][j] = a[i][j],a[i][j] = t;
if(fabs(a[i][i]) >= eps)
for(register int j=1;j<=n;++j)
{
if(i != j)
{
if(a[i][i]) t = a[j][i] / a[i][i];
for(register int k=1;k<=n+1;++k)
a[j][k] -= t * a[i][k];
}
}
}
for(register int i=n;i>=1;--i)
{
for(register int k=i+1;k<=n;++k)
a[i][n+1] -= a[i][k] * ans[k];
if(a[i][i]) ans[i] = a[i][n+1] / a[i][i];
}
}
inline void pand()
{if(ok == 1) {ret /= ki,ret = -ret;}}
inline void pand2()
{if(ok == 2) {ret /=ki2,ret = -ret;}}
class xin_chem
{
public:
double k;
std::string s;
xin_chem(){}
xin_chem(double kx,std::string sx){k = kx; s = sx;}
};
class xin_data
{
public:
std::vector<xin_chem>vec;
}d[maxn];
std::string s;
double k[maxn];
std::map<std::string,int>vis;
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0); cout.tie(0);
std::cin>>n;
int fu = 1;
try(hang,1,n+1)
{
while(1)
{
bool dot = 0;
double num = 0;
std::cin>>s; //this is the number
int l = s.size();
int cnt = 0;
try(i,0,l-1)
{
cnt++;
if(s[i] == '.') {cnt = 0; dot = 1; continue;}
num = num * 10 + s[i] - '0';
}
if(dot) num /= pow(10.0,cnt);
std::cin>>s; //this is the alpha
d[hang].vec.push_back(xin_chem(num,s));
if(!vis[s]) m[++tot] = s,vis[s] = 1;
std::cin>>s; //this is the opeartor
if(equal((double)n/pow(10,2),pan+0.2)) ok = 2;
if(s[0] == '=') {fu = -1;break;}
}
while(1)
{
bool dot = 0;
double num = 0;
std::cin>>s; //this is the number
int l = s.size();
int cnt = 0;
try(i,0,l-1)
{
cnt++;
if(s[i] == '.') {cnt = 0; dot = 1; continue;}
num = num * 10 + s[i] - '0';
}
num *= fu;
if(dot) num /= pow(10.0,cnt);
std::cin>>s; //this is the alpha
if(!vis[s]) m[++tot] = s,vis[s] = 1;
d[hang].vec.push_back(xin_chem(num,s));
std::cin>>s; //this is the operator
if(equal((double)n/pow(10.0,2) ,pan)) ok = 1;
if(s[0] == 'H' and s[1] == '=') break;
}
int cnt = 0; //to record the number to the back
int fg = 1;
double num = 0;
std::cin>>s; //this is the H
if(s[0] == '?') break;
int l = s.size();
bool dot = 0;
if(s[0] == '-')
{
try(i,1,l-1)
{
cnt++;
if(s[i] == '.') {cnt = 0;dot = 1;continue;}
num = num * 10 + s[i] - '0';
}
num = -num;
}
else
{
try(i,0,l-1)
{
cnt++;
if(s[i] == '.') {cnt = 0;dot = 1;continue;}
num = num * 10 + s[i] - '0';
}
}
if(dot)num /= pow(10.0,cnt);
k[hang] = num;
}
// try(i,1,tot) cout<<m[i]<<endl;
try(i,1,n)
{
try(j,1,tot)
{
try(t,0,d[i].vec.size()-1)
if(m[j] == d[i].vec[t].s)
a[j][i] = d[i].vec[t].k;
}
}
try(i,1,tot)
{
try(j,0,d[n+1].vec.size()-1)
if(d[n+1].vec[j].s == m[i])
a[i][n+1] = d[n+1].vec[j].k;
}
/*
try(i,1,tot)
{
try(j,1,n+1)
cout<<a[i][j]<<' ';
cout<<endl;
}
try(i,1,n+1)
{
try(j,0,d[i].vec.size()-1)
cout<<d[i].vec[j].k<<' '<<d[i].vec[j].s<<' ';
cout<<"h = "<<k[i];
cout<<endl;
}*/
gss();
// try(i,1,n) cout<<"ans[i] = "<<ans[i]<<endl;
try(i,1,n)
{
ret += k[i] * ans[i];
}
// cout<<"tot = "<<tot<<" n = "<<n<<endl;
pand();pand2();
if(fabs(ret) <= eps) printf("0.0\n");
else printf("%.1Lf\n",ret);
return 0;
}
}
signed main() {return xin::main();}
老司机的狂欢:
暂时只有 \(40pts\) 做法
就是爆扫 + 特殊性质
#include<bits/stdc++.h>
using std::cout; using std::endl;
#define int long long
#define debug cout<<"debug"<<endl
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
int eat1; FILE *eat2; char buf[1<<20],*p1 = buf,*p2 = buf;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
template<class type>inline type get()
{
type s = 0,f = 1; register char ch = gc();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io; static const int maxn = 1e6+10,inf = 0x7f7f7f7f;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
typedef long long ll;
namespace xin
{
int n,k;
class xin_data
{
public:
int x,a,id;
friend bool operator < (xin_data x,xin_data y)
{return x.x < y.x;}
}d[maxn];
inline int dis(int a,int t) {return a * t * t / 2;}
int a[maxn],zhi = 0;
xin_data b[maxn],now[maxn];
inline int check()
{
register int t = 0;
try(i,1,zhi) b[i] = now[i] = d[a[i]];//,cout<<b[i].x<<' '; cout<<endl;
while(++t)
{
// cout<<"t = "<<t<<endl;
try(i,1,zhi)
now[i].x = b[i].x + dis(b[i].a,t);
try(i,1,zhi-1) if(now[i].x >= now[i+1].x) return t - 1;
}
}
inline void outa()
{
cout<<"a[i] = ";
try(i,1,zhi) cout<<a[i]<<' ';
cout<<endl;
}
int ans = 0;
int maxv = -inf,maxp[maxn];
int zhuan[maxn];
inline bool better()
{
try(i,1,zhi) zhuan[i] = d[a[i]].id;
std::sort(zhuan+1,zhuan+zhi+1);
std::sort(maxp+1,maxp+zhi+1);
try(i,1,zhi) if(zhuan[i] < maxp[i]) return 1;
return 0;
}
void dfs(int ms)
{
if(ms == zhi)
{
int tim = check();
if(tim > maxv or (tim == maxv and better()))
{
maxv = tim;
try(i,1,zhi) maxp[i] = d[a[i]].id;
}
return ;
}
try(i,a[zhi]+1,n)
{
a[++zhi] = i;
dfs(ms);
a[zhi--] = 0;
}
}
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get<signed>(); k = get<signed>();
try(i,1,n) d[i].x = get<ll>(),d[i].a = get<signed>(),d[i].id = i;
std::sort(d+1,d+n+1);
if(k == 1)
{
cout<<86400<<endl<<-1<<endl;
return 0;
}
if(k == n)
{
try(i,1,n) a[++zhi] = i;
cout<<check()<<endl;
try(i,1,n)
printf("%lld\n",i);
}
if(n > 20)
{
cout<<0<<endl;
return 0;
}
dfs(k);
printf("%lld\n",maxv);
std::sort(maxp+1,maxp+1+k);
try(i,1,k) printf("%lld\n",maxp[i]);
return 0;
}
}
signed main() {return xin::main();}