咕咕咕以后一定好好看题(
惨痛的教训(
T1
因为根之间相差大于等于1,所以我们可以枚举长度为1的区间,然后就是浮点数的二分查找,设个eps精度限制就行
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> using namespace std; int cnt; double a,b,c,d; double eps = 0.001; inline double f(double x){ return x * x * x * a + x * x * b + x * c + d; } int main(){ freopen("equ.in","r",stdin); freopen("equ.out","w",stdout); scanf("%lf%lf%lf%lf",&a,&b,&c,&d); //printf("%lf %lf %lf\n",f(0),f(2),f(100)); for(int i=-100;i<=100 ;++i){ double l = i,r = i + 1; double x1 = f(l),x2 = f(r); if(x1 == 0.0){ cnt++; printf("%.2lf ",l); //continue; } if(x1 * x2 < 0){ while(l + eps <= r){ double mid = (l + r) / 2; if(f(mid) * f(r) <= 0)l = mid; else r = mid; } printf("%.2lf ",r); cnt++; } if(cnt == 3)break; } } //1 -5 -4 20
T2
找规律我们可以发现,这个东西中心对称,并且 i+2^k的区间都是由i的区间加上2^k过来的,模拟就行
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> using namespace std; typedef int ll; ll n,m; int a[1005][1005]; int main(){ freopen("match.in","r",stdin); freopen("match.out","w",stdout); scanf("%d",&m); n = (1 << m); int now = 1; a[1][1] = 1; int mm = m; while(m--){ for(int i=1;i<=now;++i) for(int j=1;j<=now;++j) a[i][j+now] = a[i][j] + now; for(int i=1;i<=now;++i) for(int j=1;j<=now;++j) a[i+now][j] = a[i][j+now],a[i+now][j+now] = a[i][j]; now = now << 1; } for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j)printf("%d ",a[i][j]); putchar('\n'); } }
快速幂
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> #define int long long using namespace std; typedef long long ll; inline int qmid(int a,int b,int c){ int res = 1,base = b; while(a){ if(a&1)res = res * base % c; base = base * base % c; a >>= 1; } return res; } inline int read(){ register int x=0,f=1; register char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*f; } signed main(){ freopen("mod.in","r",stdin); freopen("mod.out","w",stdout); int a,b,p; a=read(),b=read(),p=read(); int x = qmid(b,a,p); printf("%lld^%lld mod %lld=%lld",a,b,p,x); }
没看见step->痛失100分 两位数没有空格->痛失60分 多打一个空格->再次痛失60分
可以发现,除了最后四步,都是把o *最右边的交换,最后4步的话就是这么走的(可以这么理解)然后就做完了
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> #define hahaha using namespace std; string s1[4] = {"ooo*o**--*", "o--*o**oo*", "o*o*o*--o*", "--o*o*o*o*"}; char s[300]; int n; int cnt; void print(){ printf("step%2d:",cnt++); for(int i=0;i<n*2+2;++i)putchar(s[i]); putchar('\n'); } inline void f(int x,int y){ swap(s[x],s[y]); swap(s[x+1],s[y+1]); print(); } int main(){ #ifdef hahaha freopen("chessman.in","r",stdin); freopen("chessman.out","w",stdout); #endif scanf("%d",&n); //int cnt = 0; for(int i=0;i<n;++i)s[i] = 'o'; for(int i=n;i<n*2;++i)s[i] = '*'; s[n*2] = s[n*2+1] = '-'; print(); int len = n; while(1){ f(len-1,len*2); len--; if(len == 3)break; f(len,len*2); } string s2; for(int i=0;i<n-4;++i)s2+="o*"; for(int i=0;i<4;++i){ printf("step%2d:",cnt++); cout << s1[i] << s2 << endl; } }