# 2019 Multi-University Training Contest 5

http://acm.hdu.edu.cn/contests/contest_show.php?cid=852

## 1004. Equation

#include<bits/stdc++.h>
using namespace std;

// #define int long long

x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf long double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-10;
const int mod = 1e9+7;

struct data {int a,b;lf x;}a[maxn],sta[maxn];
int n,top;

int cmp(data a,data b) {return a.x<b.x;}

data make(int a,int b) {return (data){a,b,(lf)b/(lf)a};}

void solve() {
int c;
sort(a+1,a+n+1,cmp);top=0;
if((lf)sumb/suma<a[1].x-eps) sta[++top]=make(suma,sumb);
a[n+1].x=2e9;
for(int i=1;i<=n;i++) {
suma+=a[i].a*2,sumb-=a[i].b*2;lf x;
if(suma==0) {
if(sumb==0) return puts("-1"),void();
continue;
}else x=(lf)sumb/suma;
if(a[i].x<=x&&x<=a[i+1].x) sta[++top]=make(suma,sumb);
}sort(sta+1,sta+top+1,cmp);
int ans=0;
for(int i=1;i<=top;i++) {
int &a=sta[i].a,&b=sta[i].b,f=1;
if(a<0) f=-f,a=-a;if(b<0) f=-f,b=-b;
if(b==0) {a=1;if(!(a==sta[i-1].a&&b==sta[i-1].b)) ans++;continue;}
int t=__gcd(a,b);a/=t,b/=t;
if(f==-1) b=-b;if(!(a==sta[i-1].a&&b==sta[i-1].b)) ans++;
}printf("%d%c",ans,ans?' ':'\n');
for(int i=1;i<=top;i++)
if(!(sta[i].a==sta[i-1].a&&sta[i].b==sta[i-1].b)) {
int a=sta[i].a,b=sta[i].b;
if(b==0) {printf("0/1%c",(--ans)?' ':'\n');continue;}
printf("%d/%d%c",b,a,(--ans)?' ':'\n');
}
}

signed main() {
return 0;
}


## 1007. Permutation 2

$$\cdots,n-1,n$$或者$$\cdots,n-3,n-1,n-2,n$$，其他的要么不合法要么就可以归纳到这两种里面。

#include<bits/stdc++.h>
using namespace std;

x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 998244353;

int f[maxn];

void solve() {
int x,y,n,a,b;
if(y-x==1&&x!=1&&y!=n) return puts("0"),void();
if(y-x<=2) return puts("1"),void();
if(x==1) a=1;else a=x+1;
if(y==n) b=n;else b=y-1;
write(f[b-a+1]);
}

int main() {
f[1]=1,f[2]=1,f[3]=1;
for(int i=4;i<maxn;i++) f[i]=(f[i-1]+f[i-3])%mod;
// for(int i=1;i<=20;i++) printf("%d %d\n",i,f[i]);;