一本通刷题


一本通
分治part
1
http://ybt.ssoier.cn:8088/problem_show.php?pid=1241

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
bool check(double x)
{
	return (x*x*x*x*x-15*x*x*x*x+85*x*x*x-225*x*x+274*x-121)>0;
}

int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	double l=1.5,r=2.4;
	while(r-l>eps)
	{
		double mid=(l+r)*1.0/2;
		if(check(mid))l=mid;
		else r=mid;
	}
	printf("%.6lf\n",r);
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


2

非常离谱的一道题,为什么非要说存在限制函数,明明没有用stl

http://ybt.ssoier.cn:8088/problem_show.php?pid=1239

归并排序
点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
//mt19937 mrand(random_device{}());
//template ostream& operator <<(ostream& out, const pair &p) {
//    return out << "(" << p.x << " " << p.y << ")";
//}
//template ostream& operator <<(ostream& out, const vector &v) {
//    rep(i, 0, sz(v)) {
//        if(i) out << " ";
//        out << v[i];
//    }
//    return out;
//}
//int rnd(int x){return mrand()%x;}
//ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
//ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
//ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
///*ll read()
//{
//    ll x=0,f=1;char c=getchar();
//    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
//    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
//    return f*x;
//}*/
////#include 
////#include 
////#include 
////#include 
////#include 
////using namespace std;
////int main()
////{
////    int ok = 0;
////    int n = 50;
////    for (int i = 1; i <= n; ++i)
////    {
////        system("make.exe > make.txt");
////        system("std.exe < make.txt > std.txt");
////        double begin = clock();
////        system("baoli.exe < make.txt > baoli.txt");
////        double end = clock();
////
////        double t = (end - begin);
////        if (system("fc std.txt baoli.txt"))
////        {
////            printf("测试点#%d Wrong Answer\n", i);
////        }
////        else if (t > 1000) //1秒
////        {
////            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
////        }
////        else
////        {
////            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
////            ok++; //AC数量+1
////        }
////    }
////    printf("\n");
////    double res = 100.0 * ok / n;
////    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
////
////    Sleep(1000); //休眠1秒,为了节约对拍次数。
////}
//inline int read()
//{
//    int x=0;
//    char ch;
//    bool fx=false;
//    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
//    if(ch=='-')fx=true,ch=getchar();
//    for(;ch>47&&ch<58;ch=getchar())
//        x=(x<<1)+(x<<3)+(ch^48);
//    return fx?-x:x;
//}
const int N=2e5+52;
int n;
int a[N],b[N],tmp[N];
void merge_sort(int q[],int l,int r)
{
	if(l>=r) return;
	int mid=l+r>>1;
	merge_sort(q,l,mid),merge_sort(q,mid+1,r);
	int k=0,i=l,j=mid+1;
	while(i<=mid&&j<=r)
	{
		if(q[i] in.txt");
//		system("brute.exe < in.txt > brute.txt");
//		system("std.exe < in.txt > std.txt");
//		if(system("fc std.txt brute.txt"))
//			break;
//	}
//#endif
//#ifdef my_dp2
//    while (1) //一直循环,直到找到不一样的数据
//    {
//        system("data.exe");
//        system("baoli.exe");
//        system("std.exe");
//        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
//            break;                          //不一样就跳出循环
//    }
//#endif
//	clock_t start,end;
//    start=clock();
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d\n",a[i]);
	merge_sort(a,1,n);
	int cnt=1;
	rep(i,2,n) 
	{
		if(a[i]!=a[i-1]) printf("%d %d\n",a[i-1],cnt),cnt=1;
		else cnt++;
	}
	if(a[n]!=a[n-1]) printf("%d %d\n",a[n-1],cnt);
	else printf("%d %d\n",a[n],++cnt);
//    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


3

http://ybt.ssoier.cn:8088/problem_show.php?pid=1245

归并排序

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+52;
int n;
int tmp[N],a[N];
void merge_sort(int q[],int l,int r)
{
	if(l>=r) return;
	int mid=l+r>>1;
	merge_sort(q,l,mid),merge_sort(q,mid+1,r);
	int k=0,i=l,j=mid+1;
	while(i<=mid&&j<=r)
	{
		if(q[i] in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i]=read();
	merge_sort(a,1,n);
	rep(i,2,n) if(a[i]!=a[i-1]) printf("%d ",a[i-1]);
    if(a[n]!=a[n-1]) printf("%d %d\n",a[n-1],a[n]);
    else printf("%d\n",a[n]);
	end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


4

归并排序

http://ybt.ssoier.cn:8088/problem_show.php?pid=1235

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int n,t;
int tmp[N],a[N];
void merge_sort(int q[],int l,int r)
{
	if(l>=r) return;
	int mid=l+r>>1;
	merge_sort(q,l,mid),merge_sort(q,mid+1,r);
	int k=0,i=l,j=mid+1;
	while(i<=mid&&j<=r)
	{
		if(q[i]>q[j]) tmp[k++]=q[i++];
		else tmp[k++]=q[j++];
	}
	while(i<=mid)  tmp[k++]=q[i++];
	while(j<=r) tmp[k++]=q[j++];
	for(int i=l,j=0;i<=r;i++,j++) a[i]=tmp[j];
}
int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i]=read();
	t=read(); 
	merge_sort(a,1,n);
	rep(i,1,t+1) printf("%d\n",a[i]); 
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


5

http://ybt.ssoier.cn:8088/problem_show.php?pid=1237

不开longlong见祖宗,到目前为止犯的错大概有。
空间开小了,越界了,类型开错了,longlong,以及输入错误,还有多组数据的初始化。这些都是绝对不能错的。

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int n;
int a[N],tmp[N];
ll merge_sort(int q[],int l,int r)
{
	if(l>=r) return 0;
	int mid=l+r>>1;
	ll ans=merge_sort(q,l,mid)+merge_sort(q,mid+1,r);
	int k=0,i=l,j=mid+1;
	while(i<=mid&&j<=r)
	{
		if(q[i]<=q[j]) tmp[k++]=q[i++];
		else tmp[k++]=q[j++],ans+=mid-i+1;//why choose i as the standard?because it calculate the number after it in case the prowhile
	}//if we choose j,we may fail to calculate the j after.
	while(i<=mid) tmp[k++]=a[i++];
	while(j<=r) tmp[k++]=a[j++];
	for (int i=l,j=0;i<=r;i++,j++) a[i]=tmp[j];
	return ans;
}
int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i]=read();
	printf("%lld\n",merge_sort(a,1,n));
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


6

http://ybt.ssoier.cn:8088/problem_show.php?pid=1240

二分查找

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int a[N],n,m; 

int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	int n;
	n=read();
	rep(i,1,n+1) a[i]=read();
	m=read();
	while(m--)
	{
		int t;t=read();
		int l=1,r=n;
		while(l>1;
			if(a[mid]>=t) r=mid;
			else l=mid+1; 
		}
		if(r==1) printf("%d\n",a[r]);
		else if(a[r]
7

http://ybt.ssoier.cn:8088/problem_show.php?pid=1328

逆序对的裸题

晚上看到了dl的NOI记,xm。不过也看到了大佬的训练强度,每天至少一套模拟5小时。
寒假自己也要这个干。

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int n;
int a[N],tmp[N];
ll merge_sort(int q[],int l,int r)
{
	if(l>=r) return 0;
	int mid=l+r>>1;
	ll ans=merge_sort(q,l,mid)+merge_sort(q,mid+1,r);
	int k=0,i=l,j=mid+1;
	while(i<=mid&&j<=r)
	{
		if(q[i]<=q[j]) tmp[k++]=q[i++];
		else tmp[k++]=q[j++],ans+=mid-i+1;//why choose i as the standard?because it calculate the number after it in case the prowhile
	}//if we choose j,we may fail to calculate the j after.
	while(i<=mid) tmp[k++]=a[i++];
	while(j<=r) tmp[k++]=a[j++];
	for (int i=l,j=0;i<=r;i++,j++) a[i]=tmp[j];
	return ans;
}
int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i]=read();
	printf("%lld\n",merge_sort(a,1,n));
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}
8

http://ybt.ssoier.cn:8088/problem_show.php?pid=1326

快速幂的分治写法

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
int b,p,k;
int cal(int p)//快速幂的过程 
{
	int tmp;
	if(p==0) return 1;
	tmp=cal(p/2)%k;//p的话由一半得到,类似于等比数列求和 
	tmp=(tmp*tmp)%k;//到底的时候也符合这个过程,余1,刚好得到1的时候的模 
	if(p%2==1) tmp=(tmp*b)%k;
	return tmp; 
}

int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	b=read(),p=read(),k=read(); 
	int tmp=b;b%=k;
	printf("%d^%d mod %d=%d",tmp,p,k,cal(p)); 
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


http://ybt.ssoier.cn:8088/problem_show.php?pid=1234

犯了很严重的错误,数组越界

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e4;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
int t;
string n;
int cal(int p)
{
	int tmp;
	if(p==0) return 1;
	tmp=cal(p/2)%10000;
	tmp=(tmp*tmp)%10000;
	if(p%2==1) tmp=(tmp*2011)%10000;
	return tmp;	 
}
int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	t=read();
	while(t--)
	{
		cin>>n;;int len=n.size();//万位往后全是1 
		int res=0;
		for(int i=len-4;i=0) res=res*10+n[i]-'0'; 
		printf("%d\n",cal(res));//数组越界 
	} 
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


10

http://ybt.ssoier.cn:8088/problem_show.php?pid=1236

贪心加排序

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=5e4+520;
int n;
struct inter
{
	int s,e;
	bool operator <(const inter & w) const 
	{
		return s in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i].s=read(),a[i].e=read(); 
    sort(a+1,a+n+1);
    int last=a[1].e;
	rep(i,2,n+1)
	{
		if(a[i].s<=last) last=max(last,a[i].e);
		else {puts("no");return 0;}
	}
	printf("%d %d\n",a[1].s,last);
	end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


11

http://ybt.ssoier.cn:8088/problem_show.php?pid=1327

类似于模拟,每次运动两个,然后到基例的时候,特殊处理

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e3+52;
char a[N];
int n,st,sp;
void print()
{
	printf("step%2d:",st++);
	rep(i,1,2*n+3) printf("%c",a[i]); 
	puts("");
}
void move(int m)
{
	a[sp]=a[m];
	a[sp+1]=a[m+1];
	a[m]=a[m+1]='-';
	sp=m;
	print(); 
}
void mv(int m)
{
	if(m==4)//基例 
	{
		move(4),move(8),move(2),move(7),move(1);
	}
	else
	{
		move(m);//每次把最后两个移动,然后还差n-1次 
		move(2*m-1);
		mv(m-1);
	}
}
int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i]='o';
	rep(i,n+1,2*n+1) a[i]='*';
	a[2*n+1]=a[2*n+2]='-';
	st=0;
	sp=2*n+1;
	print();
	mv(n);
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


12

http://ybt.ssoier.cn:8088/problem_show.php?pid=1325

很有意思的一道题有点像数回,通过对子问题的处理来处理大的问题,这是分治的核心,在于子问题和整体的问题具有一个关联性。

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e3+520;
int g[N][N];
int m;
void build(int size)
{
	if(size==0) return;
	build(size>>1);
	rep(i,0,size) rep(j,0,size) g[i][j+size]=g[i][j]+size;
	rep(i,0,size) rep(j,0,size) g[i+size][j+size]=g[i][j],g[i+size][j]=g[i][j+size];	
}
int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	m=read();
	int n=1<>1);
	rep(i,0,n) 
	{
		rep(j,0,n) printf("%d ",g[i][j]);
		puts("");
	}	
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


13

http://ybt.ssoier.cn:8088/problem_show.php?pid=1242

二分答案,能小的,那么就有可能的大的,如果大的不行,那么只能选择更小的。
其次选择,向什么方向,以及不能div0,选择什么样的二分。

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+52;
int n,k;
int a[N];

bool check(int t)
{
	int ans=0; 
	rep(i,0,n) 
	{
		ans+=a[i]/t;	
	}
	return ans>=k; 
} 
int main()//二分答案,具有二分性,小的一定更容易,大的一定更困难,条件存在一个松散性 
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read(),k=read();
	int maxn=0;
	rep(i,0,n) 
	{
		double w;scanf("%lf",&w);
		a[i]=int(w*100+0.5); maxn=max(maxn,a[i]);
	}
	int l=0,r=maxn;//设置哨兵,对于能取到的值选择,不能的择不选 
	while(l
14 二分答案的关键在于松和紧,要找到松和紧的地方,也就是二分性

http://ybt.ssoier.cn:8088/problem_show.php?pid=1243

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int n,m;
int a[N];
bool check(int t)
{
	ll ans=0,cnt=0;
	rep(i,1,n+1)
	{
		ans+=a[i];//如果是从 1开始的话,则不需要特判了 
		if(ans>t)//最后一段算不算 
		{
			if(a[i]>t) return 0;
			else ans=a[i],cnt++;	
		}
	}
	if(ans in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read(),m=read();
	ll tot=0;
	rep(i,1,n+1) a[i]=read(),tot+=a[i];
	ll l=1,r=tot;
	while(l>1;
		if(check(mid))r=mid;
		else l=mid+1;
	} 
	printf("%lld\n",r);
	end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


15

双指针,不太算二分,只有二分性,就是如果最外面的不成立,那么肯定要往里面收缩。

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int n,m;
int a[N]; 

int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	n=read();
	rep(i,1,n+1) a[i]=read();
	sort(a+1,a+1+n);
	m=read();
	int i=1,j=n;
	while(im) j--;
		else {printf("%d %d\n",a[i],a[j]);return 0;}
 	}
 	puts("No");
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


16

http://ybt.ssoier.cn:8088/problem_show.php?pid=1247

二分答案,松和紧,然后明确二分方向,建立check函数。变量不要重名

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-9;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const int N=1e5+520;
int ed,n,m;
int a[N];
bool check(int t)
{
	int cnt=0,dis=0;
	rep(i,1,n+1)
		if(a[i]-dis in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	ed=read(),n=read(),m=read();
	rep(i,1,n+1) a[i]=read();
	ll l=1,r=ed;
	while(l>1;
		if(check(mid)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


17

二分查找
在圆周角具有周期性
大于则回退,小于则增加角度,角度和长度正比
和l2比较
用好三角形

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-12;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
const double PI=asin(1.0);
double l1,n;
double c;


int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	scanf("%lf%lf%lf",&l1,&n,&c);
	double l2=(1+n*c)*l1;
	double l=0,r=asin(1.0),mid;
	if(n*c*l1<=eps) printf("%.3lf\n",0.0);
	else 
	{
		while(r-l>eps)
		{
			mid=(r+l)/2.0;
			if(l1/2/sin(mid)*mid*2>l2) r=mid;
			else l=mid;
		}
		printf("%.3lf\n",l1/2/sin(l)-l1/2/sin(l)*cos(l));
	}  
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}


18

http://ybt.ssoier.cn:8088/problem_show.php?pid=1238

Ive thought that it was a binary search problem.but it turns out that it's just a easy enumerated problem.you just need to add the x by 0.01 and check each answer,if it's right then it's the ans_x.

点击查看代码
#include
#define rep(i,l,r) for(int i=int(l);i=int(l);i--)
#define repg(i,l,r) for(i=int(l);i=int(l);i--)
#define rept(i,t) for(int i=int(h[t]);~i;i=ne[i])
#define reph(i,t,h) for(int i=int(h[t]);~i;i=ne[i])
#define x first
#define y second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long lll;
typedef pair PII;
typedef pair PDD;
const int INF=0x3f3f3f3f,mod=1e9+7;
const ll INFF=1e18;
const double eps=1e-6;
mt19937 mrand(random_device{}());
template ostream& operator <<(ostream& out, const pair &p) {
    return out << "(" << p.x << " " << p.y << ")";
}
template ostream& operator <<(ostream& out, const vector &v) {
    rep(i, 0, sz(v)) {
        if(i) out << " ";
        out << v[i];
    }
    return out;
}
int rnd(int x){return mrand()%x;}
ll qmi(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll qmul(ll a,ll b){ll res=0;a%=mod;while(b){if(b&1) res=(res+a)%mod;a=(a+a)%mod;b>>=1;} return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return f*x;
}*/
//#include 
//#include 
//#include 
//#include 
//#include 
//using namespace std;
//int main()
//{
//    int ok = 0;
//    int n = 50;
//    for (int i = 1; i <= n; ++i)
//    {
//        system("make.exe > make.txt");
//        system("std.exe < make.txt > std.txt");
//        double begin = clock();
//        system("baoli.exe < make.txt > baoli.txt");
//        double end = clock();
//
//        double t = (end - begin);
//        if (system("fc std.txt baoli.txt"))
//        {
//            printf("测试点#%d Wrong Answer\n", i);
//        }
//        else if (t > 1000) //1秒
//        {
//            printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
//        }
//        else
//        {
//            printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
//            ok++; //AC数量+1
//        }
//    }
//    printf("\n");
//    double res = 100.0 * ok / n;
//    printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
//
//    Sleep(1000); //休眠1秒,为了节约对拍次数。
//}
inline int read()
{
    int x=0;
    char ch;
    bool fx=false;
    do ch=getchar();while(~ch&&ch!='-'&&(ch<48||ch>57));
    if(ch=='-')fx=true,ch=getchar();
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return fx?-x:x;
}
double a,b,c,d;
double cal(double t)
{
	return a*t*t*t+b*t*t+c*t+d;
} 
double x1,x2,x3;
double calculate(double x)
{
    double ans=0;
    double y=1;
 
    for(int i=1;i<=3;i++)
        y*=x;
    y*=a;
    ans+=y;
 
    y=1;
    for(int i=1;i<=2;i++)
        y*=x;
    y*=b;
    ans+=y;
 
    y=1;
    y*=x;
    y*=c;
    ans+=y;
 
    ans+=d;
    return ans;
}

int main()
{
#ifdef my_test
 	freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
#ifdef my_dp
	while(1)
	{
		system("data.exe > in.txt");
		system("brute.exe < in.txt > brute.txt");
		system("std.exe < in.txt > std.txt");
		if(system("fc std.txt brute.txt"))
			break;
	}
#endif
#ifdef my_dp2
    while (1) //一直循环,直到找到不一样的数据
    {
        system("data.exe");
        system("baoli.exe");
        system("std.exe");
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
    }
#endif
	clock_t start,end;
    start=clock();
	scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
	double t=-100;//x^3,which means the epision will not exceed 1e-6;
	while(t-100<=eps)//the epision cannot be defined too small which can lead to some mistakes 
	{
		if(fabs(cal(t))<=eps) break;
		t+=0.01;
	}
	x1=t;
	t+=0.01;
	while(t-100<=eps)
	{
		if(fabs(cal(t))<=eps) break;
		t+=0.01;
	}
	x2=t;
	t+=0.01;	
	while(t-100<=eps)
	{
		if(fabs(cal(t))<=eps) break;
		t+=0.01;
	}
	x3=t;
	printf("%.2lf %.2lf %.2lf\n",x1,x2,x3);
    end=clock();
//    printf("%lfms\n",(double)(end-start)/CLOCKS_PER_SEC*1000);
    return 0;
}