diff --git "a/1carus/CDOJ_\346\237\261\345\223\245\347\232\204\346\234\200\345\244\247\345\214\272\351\227\264\345\222\214.cpp" "b/1carus/CDOJ_\346\237\261\345\223\245\347\232\204\346\234\200\345\244\247\345\214\272\351\227\264\345\222\214.cpp" deleted file mode 100644 index 3bc39ff2..00000000 --- "a/1carus/CDOJ_\346\237\261\345\223\245\347\232\204\346\234\200\345\244\247\345\214\272\351\227\264\345\222\214.cpp" +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include -#include -#define endl '\n' - -using namespace std; - -const int MAXN = 5e6 + 5; -int pre[MAXN],suf[MAXN],n,num[MAXN]; - -int main() -{ - while(scanf("%d",&n) == 1) - { - int i; - for(i = 1;i <= n;i++) - { - scanf("%d",&num[i]); - } - - memset(pre,-0x3f,sizeof(pre)); - memset(suf,-0x3f,sizeof(suf)); - - int sum = 0; - for(i = 1;i <= n;i++) - { - sum += num[i]; - pre[i] = max(sum,pre[i - 1]); - if(sum < 0)sum = 0; - } - - sum = 0; - for(i = n;i >= 0;i--) - { - sum += num[i]; - suf[i] = max(sum,suf[i + 1]); - if(sum < 0)sum = 0; - } - - int ans = -0x3f3f3f3f; - for(i = 1;i <= n;i++) - { - ans = max(ans,pre[i - 1] + suf[i + 1]); - } - - cout << ans << endl; - } - return 0; -} diff --git a/1carus/CF2016-5-12C.cpp b/1carus/CF2016-5-12C.cpp deleted file mode 100644 index 1d3841d8..00000000 --- a/1carus/CF2016-5-12C.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include -#include -#include -#include -#include -#include -#define endl '\n' -#define max(a,b) (a > b ? a : b) -#define min(a,b) (a < b ? a : b) - -using namespace std; - -const int MAXN = 100005; -const double eps = 1e-8; -struct node{ - double x,y; -}p,q,s,num[MAXN]; - -struct distan{ - double val; - int index; -}f1[2],f2[2]; - -int target[MAXN]; -int n; - -double dist(double x1,double y1,double x2,double y2) -{ - double t1 = (x1 - x2) * (x1 - x2); - double t2 = (y1 - y2) * (y1 - y2); - - return sqrt(t1 + t2); -} - -int main() -{ - while(scanf("%lf %lf %lf %lf %lf %lf",&p.x,&p.y,&q.x,&q.y,&s.x,&s.y) == 6) - { - memset(target,0,sizeof(target)); - - scanf("%d",&n); - int i; - for(i= 0;i < n;i++) - { - scanf("%lf %lf",&num[i].x,&num[i].y); - } - - f1[0].val = f1[0].val = -0x7fffffff * 1.0; - f2[0].val = f2[0].val = -0x7fffffff * 1.0; - - int index1,index2; - double ans = 0; - for(i = 0;i < n;i++) - { - double t3 = dist(num[i].x,num[i].y,s.x,s.y); - double t1 = t3 - dist(num[i].x,num[i].y,p.x,p.y); - double t2 = t3 - dist(num[i].x,num[i].y,q.x,q.y); - - ans += 2 * t3; - if(t1 > f1[0].val) - { - f1[1].val = f1[0].val; - f1[1].index = f1[0].index; - f1[0].val = t1; - f1[0].index = i; - } - else if(t1 > f1[1].val) - { - f1[1].val = t1; - f1[1].index = i; - } - - if(t2 > f2[0].val) - { - f2[1].val = f2[0].val; - f2[1].index = f2[0].index; - f2[0].val = t2; - f2[0].index = i; - } - else if(t2 > f2[1].val) - { - f2[1].val = t2; - f2[1].index = i; - } - } - - if(n == 1) - { - printf("%.12lf\n",ans - max(f1[0].val,f2[0].val)); - continue; - } - - if(f1[0].index == f2[0].index) - { - ans = ans - max(max(max(f1[0].val + f2[1].val,f1[1].val + f2[0].val),f1[0].val),f2[0].val); - } - else ans = ans -max(max((f1[0].val + f2[0].val),f1[0].val),f2[0].val); - - printf("%.12lf\n",ans); - } - return 0; -} diff --git a/1carus/CodeForces 451B.cpp b/1carus/CodeForces 451B.cpp deleted file mode 100644 index 1ca5291b..00000000 --- a/1carus/CodeForces 451B.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include -#include -#define endl '\n' -#define max(a,b) (a > b ? a : b) -#define min(a,b) (a < b ? a : b) - -using namespace std; - -const int MAXN = 1e5 + 5; - -int num[MAXN],tnum[MAXN],n; -int dp[MAXN]; - -int main() -{ - while(scanf("%d",&n) == 1) - { - int i; - //index[0] = index[1] = 0; - for(i = 1;i <= n;i++) - { - scanf("%d",&num[i]); - } - - int flag = 0,l = 0,r = 0,cont = 0; - for(i = 1;i <= n;i++) - { - if(num[i] >= num[i + 1] && i != n && flag == 0) - { - l = i; - cont++; - flag = 1; - if(cont > 1)break; - } - - if(num[i] <= num[i + 1] && flag == 1) - { - flag = 0; - r = i; - } - } - - if(r == 0 && l == 0)l = r = 1; - if(r == 0)r = n; - - if(cont > 1) - { - cout << "no" << endl; - continue; - } - - flag = 1; - if(l >= 1 && num[r] < num[l - 1])flag = 0; - if(r <= n - 1 && num[l] > num[r + 1])flag = 0; - - if(flag == 0) - { - cout << "no" << endl; - } - else - { - cout << "yes" << endl; - cout << l << " " << r << endl; - } - } - return 0; -} diff --git a/1carus/CodeForces 451C.cpp b/1carus/CodeForces 451C.cpp deleted file mode 100644 index 99912537..00000000 --- a/1carus/CodeForces 451C.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include -#include -#define endl '\n' -#define max(a,b) (a > b ? a : b) -#define min(a,b) (a < b ? a : b) - -using namespace std; - -long long x,y,z,a,b; -long long n,k; - -bool judge(long long x,long long y,long long z) -{ - if(x < 0 || y < 0 || z < 0)return false; - if(x + y + z != k)return false; - - long long mmax = max(x,max(y,z)); - - long long temp = 0; - temp += mmax - x; - temp += mmax - y; - temp += mmax - z; - - if(temp > n - k || (n - k - temp) % 3)return false; - else - { - //cout << x << " " << y << " " << z << endl; - return true; - } -} - -int main() -{ - int T; - scanf("%d",&T); - while(T--) - { - scanf("%I64d %I64d %I64d %I64d",&n,&k,&a,&b); - - z = (k - 2 * b - a) / 3; - if(judge(z + a + b,z + b,z)) - { - cout << "yes" << endl; - continue; - } - z = (k - 2*b + a) / 3; - if(judge(z + b - a,z + b,z)) - { - cout << "yes" << endl; - continue; - } - z = (k + a + 2 * b) / 3; - if(judge(z - b - a,z - b,z)) - { - cout << "yes" << endl; - continue; - } - z = (k - a + 2 * b) / 3; - if(judge(z - b + a,z - b,z)) - { - cout << "yes" << endl; - continue; - } - cout << "no" << endl; - } - return 0; -} diff --git a/1carus/POJ 3007.cpp b/1carus/POJ 3007.cpp deleted file mode 100644 index 6a91d737..00000000 --- a/1carus/POJ 3007.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include -#include -#include -#define endl '\n' -#define ll long long -#define pr(str) printf("%s\n",str) - -using namespace std; - -const int MAXN = 10005; -const int HASH = 10007; -const int SEED = 123; - -int S[MAXN]; -char pre[MAXN],suf[MAXN],str[MAXN]; - -struct HASHMAP -{ - int head[HASH],next[MAXN],sz; - unsigned ll state[MAXN]; - - void init() - { - sz = 0; - memset(head,-1,sizeof(head)); - } - - int Insert(unsigned ll val) - { - //cout< -#include -#include -#include -#include -#define endl '\n' - -using namespace std; - -const int MAXN = 1e6 + 5; - -int n; -long long dp[MAXN]; -const int MOD = 1000000007; - -void init() -{ - dp[1] = 1;dp[2] = 2;dp[3] = 4; - int i; - for(i = 4;i <= MAXN;i++) - { - dp[i] = ((dp[i - 2] % MOD * (long long)(i - 1)) % MOD + dp[i - 1] % MOD) % MOD; - } -} - -int main() -{ - init(); - int T,cont = 1; - scanf("%d",&T); - while(T--) - { - scanf("%d",&n); - cout << "Case #" << cont++ << ":" << endl; - cout << dp[n] << endl; - } - return 0; -} diff --git a/FlyingFatty/HDOJ3555.cpp b/FlyingFatty/HDOJ3555.cpp deleted file mode 100644 index 3266843a..00000000 --- a/FlyingFatty/HDOJ3555.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#define lson rt<<1,l,mid -#define rson rt<<1|1,mid+1,r -#define ll rt<<1 -#define rr rt<<1|1 -#define LL long long -#define ULL unsigned long long -#define maxn 1050 -#define maxnum 1000050 -#define eps 1e-6 -#define input freopen("input.txt","r",stdin) -#define output freopen("output.txt","w",stdout) - -/* -dp[len][0]:前len位不含49且第len位不是4 -dp[len][1]:前len位不含49且第len位为9(在加高位的4就可以符合题意了) -dp[len][2]:前len位已有49 -*/ - -__int64 n; -int digit[20]; -__int64 dp[20][5]; - -__int64 dfs(int pos,int status,bool flag){ - if (pos==0) return status==2; - if (flag&&dp[pos][status]!=-1) return dp[pos][status]; - int num=flag?9:digit[pos]; - __int64 ans=0; - for(int i=0;i<=num;i++){ - //如果前len位已经有了49,或者加上这次枚举的高位的4有了49 - if (status==2||(status==1&&i==9)) ans+=dfs(pos-1,2,flag||i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#define lson rt<<1,l,mid -#define rson rt<<1|1,mid+1,r -#define ll rt<<1 -#define rr rt<<1|1 -#define LL long long -#define ULL unsigned long long -#define maxn 1050 -#define maxnum 1000050 -#define eps 1e-6 -#define input freopen("input.txt","r",stdin) -#define output freopen("output.txt","w",stdout) - -__int64 m,n; -int digit[20]; -__int64 dp[20][5][15]; - -__int64 dfs(int pos,int status,int mod,bool flag){ - if (pos==0) return (status==2&&mod==0); - if (flag&&dp[pos][status][mod]!=-1) return dp[pos][status][mod]; - int num=flag?9:digit[pos]; - __int64 ans=0; - for(int i=0;i<=num;i++){ - int nowmod=(mod*10+i)%13; - if (status==2||(status==1&&i==3)) ans+=dfs(pos-1,2,nowmod,flag||i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#define lson rt<<1,l,mid -#define rson rt<<1|1,mid+1,r -#define ll rt<<1 -#define rr rt<<1|1 -#define LL long long -#define ULL unsigned long long -#define maxn 1050 -#define maxnum 1000050 -#define eps 1e-6 -#define input freopen("input.txt","r",stdin) -#define output freopen("output.txt","w",stdout) - -/* -函数解释: -getnewstatus: -LIS的O(nlogn) - -getonenum: -计算s中有多少个1 -*/ - -int digit[50],K; -__int64 dp[50][1<<12][12]; -__int64 L,R; - -int getnewstatus(int x,int s){ - for(int i=x;i<10;i++) - if (s&(1<>=1; - } - return num; -} - -__int64 dfs(int pos,int status,bool flag,bool zero){ - if (pos==0) return getonenum(status)==K; - if (flag&&dp[pos][status][K]!=-1) return dp[pos][status][K]; - int num=flag?9:digit[pos]; - __int64 ans=0; - for(int i=0;i<=num;i++) - //注意到0这个特殊数值 - ans+=dfs(pos-1,zero&&(i==0)?0:getnewstatus(i,status),flag||i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=505; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=1000000007; -const int INF=1000000010; -typedef double db; -typedef unsigned long long ull; -struct node { - int x,y,w; - node(){} - node(int x,int y,int w):x(x),y(y),w(w){} - bool operator < (const node a) const{ - return wR) return ; - int i,k=L,g,mid=(l+r)>>1; - if (l==r) { - for (i=L;i<=R;i++) ans[q[i].id]=p[l].w; - return ; - } - for (i=l;i<=mid;i++) add(p[i].x,p[i].y,1); - for (i=L;i<=R;i++) - if (getsum(q[i].x2,q[i].y2)-getsum(q[i].x1-1,q[i].y2)-getsum(q[i].x2,q[i].y1-1)+getsum(q[i].x1-1,q[i].y1-1)>=q[i].k) h[k++]=q[i]; - g=k; - for (i=L;i<=R;i++) - if (getsum(q[i].x2,q[i].y2)-getsum(q[i].x1-1,q[i].y2)-getsum(q[i].x2,q[i].y1-1)+getsum(q[i].x1-1,q[i].y1-1) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=500010; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=998244353; -const int INF=1000000010; -typedef double db; -typedef unsigned long long ull; -int d[N],p[N],w[N],pre[N],sub[N]; -char s[N],c[N]; -int main() -{ - int i,n,m,q,l,r,k=0; - scanf("%d%d%d", &n, &m, &q); - scanf("%s", s); - scanf("%s", c); - for (i=n;i;i--) - if (s[i-1]==')') { p[i]=p[i+1]+1;d[++k]=i; } - else { p[i]=p[i+1]-1;w[i]=d[k];k--; } - for (i=1;i<=n;i++) w[w[i]]=i; - for (i=0;i<=n+1;i++) pre[i]=i-1,sub[i]=i+1; - for (i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=1000010; -const int MAX=151; -const int mod=100000000; -const int MOD1=100000007; -const int MOD2=100000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=1000000000; -const ll INF=10000000010; -typedef double db; -typedef unsigned long long ull; -char s[N],c[N],d[N]; -int les,lec,x[10],y[10],z[10]; -int check(int w) { - int i,k=0,g=0,W=w; - memset(z,0,sizeof(z)); - while (w) { g++;z[w%10]++;w/=10; } - if (les!=W+g) return 0; - for (i=0;i<10;i++) - if (x[i]y[i]+z[i]) k++; - if (!k&&c[0]=='0') return 0; - return 1; -} -int compare(int lec,int led) { - char C,D; - for (int i=0;iD) return 0; - } - return 1; -} -void print_out(int w) { - int i,j,k=0,W=w,bo=0; - for (i=0;i<10;i++) x[i]-=y[i]; - while (w) { x[w%10]--;w/=10; } - for (i=1;i<10;i++) - for (j=1;j<=x[i];j++) d[k++]=i+'0'; - for (i=k-1;i>0;i--) d[i+x[0]]=d[i]; - if (k) for (i=1;i<=x[0];i++) d[i]='0'; - else for (i=0;ic[i-1]) bo=1;break ; - } - if (bo) { - for (i=1;ic[0]) break ; - else printf("%c", d[i]); - printf("%s", c); - for (j=i;j=c[0]) break ; - else printf("%c", d[i]); - printf("%s", c); - for (j=i;j -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=1000010; -const int MAX=151; -const int mod=100000000; -const int MOD1=100000007; -const int MOD2=100000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=1000000000; -const ll INF=1000000000010; -typedef double db; -typedef long double ldb; -typedef unsigned long long ull; -ll hea,top,t[N]; -ldb dx[N],dy[N],dp[2][N],sum[N],sump[N],sumq[N]; -int cala(ldb x,ldb y,ldb x1,ldb y1,ldb x2,ldb y2) { - return (y2-y1)*(x1-x)>=(y1-y)*(x2-x1); -} -void add(ldb x,ldb y) { - if (top-hea<1) { top++;dx[top]=x;dy[top]=y;return ; } - while (top-hea>0&&cala(x,y,dx[top],dy[top],dx[top-1],dy[top-1])) top--; - top++;dx[top]=x;dy[top]=y; -} -int main() -{ - int i,j,n,k,now,pre; - scanf("%d%d", &n, &k); - for (i=1;i<=n;i++) scanf("%I64d", &t[i]); - t[0]=0ll;sum[0]=sump[0]=sumq[0]=0.0; - for (i=1;i<=n;i++) { - sum[i]=sum[i-1]+1.0*t[i]; - sumq[i]=sumq[i-1]+1.0/t[i]; - sump[i]=sump[i-1]+sum[i]*1.0/t[i]; - } - now=pre=0; - for (i=0;i<=n;i++) dp[now][i]=sump[i]; - for (i=2;i<=k;i++) { - pre=now;now^=1;hea=1;top=0; - for (j=i;j<=n;j++) { - add(sum[j-1],sum[j-1]*sumq[j-1]-sump[j-1]+dp[pre][j-1]); - while (top-hea>0&&sumq[j]*(dx[hea]-dx[hea+1])<=dy[hea]-dy[hea+1]) hea++; - dp[now][j]=sump[j]-dx[hea]*sumq[j]+dy[hea]; - } - } - printf("%.15f\n", (db)dp[now][n]); - return 0; -} diff --git a/Fsss/cf352.2.C - Recycling Bottles b/Fsss/cf352.2.C - Recycling Bottles deleted file mode 100644 index 81e2401b..00000000 --- a/Fsss/cf352.2.C - Recycling Bottles +++ /dev/null @@ -1,67 +0,0 @@ -/* -http://blog.csdn.net/fsss_7/article/details/51386941 -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=100010; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=1000000007; -const int INF=1000000010; -typedef double db; -typedef long double ldb; -typedef unsigned long long ull; -db x[N],y[N]; -struct node { - int u; - db d; - node(){} - node(int u,db d):u(u),d(d){} - bool operator < (const node a) const{ - return d>a.d; - } -}a[N],b[N]; -db ddis(db x1,db y1,db x2,db y2) { - db x=x1-x2,y=y1-y2; - return sqrt(x*x+y*y); -} -int main() -{ - int i,n; - db xa,xb,ya,yb,X,Y; - db ans=0,ans1,ans2,ans3; - scanf("%lf%lf%lf%lf%lf%lf", &xa, &ya, &xb, &yb, &X, &Y); - scanf("%d", &n); - for (i=1;i<=n;i++) scanf("%lf%lf", &x[i], &y[i]); - for (i=1;i<=n;i++) a[i]=node(i,ddis(x[i],y[i],X,Y)-ddis(x[i],y[i],xa,ya)); - for (i=1;i<=n;i++) b[i]=node(i,ddis(x[i],y[i],X,Y)-ddis(x[i],y[i],xb,yb)); - sort(a+1,a+n+1); - sort(b+1,b+n+1); - for (i=1;i<=n;i++) ans+=2.0*ddis(X,Y,x[i],y[i]); - ans1=min(ans-a[1].d,ans+ddis(xa,ya,X,Y)); - ans2=min(ans-b[1].d,ans+ddis(xb,yb,X,Y)); - if (a[1].u==b[1].u) { - if (a[1].d+b[2].d>=a[2].d+b[1].d) ans3=ans-a[1].d-b[2].d; - else ans3=ans-a[2].d-b[1].d; - } else { - ans3=ans-a[1].d-b[1].d; - } - printf("%.10f\n", min(ans1,min(ans2,ans3))); - return 0; -} diff --git a/Fsss/hdu1848Fibonacci again and again b/Fsss/hdu1848Fibonacci again and again deleted file mode 100644 index 15e883c6..00000000 --- a/Fsss/hdu1848Fibonacci again and again +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=1010; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=1000000007; -const int INF=1000000010; -typedef double db; -typedef long double ldb; -typedef unsigned long long ull; -int a[14]={1,2,3,5,8,13,21,34,55,89,144,233,377,610}; -int q[N],p[N]; -void deal(int n) { - int i,j; - memset(q,0,sizeof(q)); - for (i=1;i<=n;i++) { - for (j=0;j<14;j++) - if (i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=100010; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=1000000007; -const int INF=1000000010; -typedef double db; -typedef unsigned long long ull; -int main() -{ - int a,i,n,t,g,xo; - scanf("%d", &t); - while (t--) { - scanf("%d", &n); - g=xo=0; - for (i=1;i<=n;i++) { - scanf("%d", &a); - xo^=a;if (a>1) g++; - } - if ((g==0&&n&1)||(g>1&&!xo)) printf("Brother\n"); - else printf("John\n"); - } - return 0; -} diff --git a/Fsss/hdu5126stars.cpp b/Fsss/hdu5126stars.cpp deleted file mode 100644 index 43732f6d..00000000 --- a/Fsss/hdu5126stars.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=50010; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=998244353; -const int INF=1000000010; -typedef double db; -typedef unsigned long long ull; -struct node { - int x,y,z,w,idx; - node(){} - node(int x,int y,int z,int w,int idx):x(x),y(y),z(z),w(w),idx(idx){} -}q[8*N],s[8*N],s1[8*N],s2[8*N]; -int cnt,f[2*N],a[2*N],ans[N]; -int cmy(node a,node b) { - if (a.y!=b.y) return a.y>1; - cdq1(l,mid);cdq1(mid+1,r); - int i,j=1,g1=0,g2=0; - for (i=l;i<=mid;i++) - if (!s[i].w) s1[++g1]=s[i]; - for (i=mid+1;i<=r;i++) - if (s[i].w) s2[++g2]=s[i]; - sort(s1+1,s1+g1+1,cmy); - sort(s2+1,s2+g2+1,cmy); - for (i=1;i<=g2;i++) { - while (j<=g1&&s1[j].y<=s2[i].y) add(s1[j++].x,1); - ans[s2[i].idx]+=s2[i].w*getsum(s2[i].x); - } - for (i=1;i>1; - cdq(l,mid);cdq(mid+1,r); - int i,g=0; - for (i=l;i<=mid;i++) - if (!q[i].w) s[++g]=q[i]; - for (i=mid+1;i<=r;i++) - if (q[i].w) s[++g]=q[i]; - sort(s+1,s+g+1,cmz); - cdq1(1,g); -} -int uniqu(int n) { - int i,cnt=1; - sort(a+1,a+n+1); - for (i=2;i<=n;i++) - if (a[i]!=a[cnt]) a[++cnt]=a[i]; - return cnt; -} -int find_x(int x) { - int l=1,r=cnt,mid=(l+r)>>1; - while (l=x) { r=mid;mid=(l+r)>>1; } - else { l=mid+1;mid=(l+r)>>1; } - return l; -} -int main() -{ - int i,n,m,t,op,x1,x2,y1,y2,z1,z2; - scanf("%d", &t); - while (t--) { - scanf("%d", &n); - m=cnt=0; - for (i=1;i<=n;i++) { - scanf("%d", &op); - if (op==1) { - scanf("%d%d%d", &x1, &y1, &z1); - a[++cnt]=x1;ans[i]=-1; - q[++m]=node(x1,y1,z1,0,0); - } else { - scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2); - a[++cnt]=x1-1;a[++cnt]=x2;ans[i]=0; - q[++m]=node(x2,y2,z2,1,i); - q[++m]=node(x1-1,y2,z2,-1,i); - q[++m]=node(x2,y1-1,z2,-1,i); - q[++m]=node(x2,y2,z1-1,-1,i); - q[++m]=node(x1-1,y1-1,z2,1,i); - q[++m]=node(x1-1,y2,z1-1,1,i); - q[++m]=node(x2,y1-1,z1-1,1,i); - q[++m]=node(x1-1,y1-1,z1-1,-1,i); - } - } - cnt=uniqu(cnt); - for (i=1;i<=cnt;i++) f[i]=0; - for (i=1;i<=m;i++) q[i].x=find_x(q[i].x); - cdq(1,m); - for (i=1;i<=n;i++) - if (~ans[i]) printf("%d\n", ans[i]); - } - return 0; -} diff --git "a/Fsss/\350\260\213\350\264\242\345\256\263\345\221\275\344\271\213\346\230\237c.cpp" "b/Fsss/\350\260\213\350\264\242\345\256\263\345\221\275\344\271\213\346\230\237c.cpp" deleted file mode 100644 index 5832f477..00000000 --- "a/Fsss/\350\260\213\350\264\242\345\256\263\345\221\275\344\271\213\346\230\237c.cpp" +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma comment(linker, "/STACK:102400000,102400000") -using namespace std; -const int N=1000010; -const int MAX=1000000100; -const int mod=100000000; -const int MOD1=1000000007; -const int MOD2=1000000009; -const double EPS=0.00000001; -typedef long long ll; -const ll MOD=998244353; -const int INF=1000000010; -typedef double db; -typedef unsigned long long ull; -char s[35],t[35]; -struct trie{ - int g,k,w,siz,d[35],val[N],tr[N][26]; - void trie_clear() { - memset(val,0,sizeof(val)); - siz=0;memset(tr,0,sizeof(tr)); - } - void trie_insert(char *ch) { - w=0;val[0]++; - while (*ch!='\0'&&tr[w][*ch-'a']) { w=tr[w][*ch-'a'];val[w]++;ch++; } - while (*ch!='\0') { tr[w][*ch-'a']=++siz;w=siz;val[w]++;ch++; } - } - void trie_delete(char *ch) { - k=w=0;d[k]=0; - while (*ch!='\0'&&tr[w][*ch-'a']) { w=tr[w][*ch-'a'];d[++k]=w;ch++; } - if (*ch!='\0') return ; - g=val[d[k]];val[0]-=g;*ch--; - for (int i=k;i;i--) { - val[d[i]]-=g; - if (!val[d[i]]) tr[d[i-1]][*ch-'a']=0; - ch--; - } - } - int find_s(char *ch) { - w=0; - while (*ch!='\0'&&tr[w][*ch-'a']) { w=tr[w][*ch-'a'];ch++; } - if (*ch=='\0') return 1; - return 0; - } -}K; -int main() -{ - int i,n; - scanf("%d", &n); - K.trie_clear(); - for (i=1;i<=n;i++) { - scanf("%s%s", s, t); - if (s[0]=='i') K.trie_insert(t); - else if (s[0]=='d') K.trie_delete(t); - else { - if (K.find_s(t)) printf("Yes\n"); - else printf("No\n"); - } - } - return 0; -} diff --git a/Helena@ssglalw/README.md b/Helena@ssglalw/README.md deleted file mode 100644 index c91f9644..00000000 --- a/Helena@ssglalw/README.md +++ /dev/null @@ -1 +0,0 @@ - # My Blog: http://www.cnblogs.com/helenawang/ diff --git a/Helena@ssglalw/hdu5510.cpp b/Helena@ssglalw/hdu5510.cpp deleted file mode 100644 index 718c27e8..00000000 --- a/Helena@ssglalw/hdu5510.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -using namespace std; -const int MAX_N = 505; -const int MAX_L = 2005; - -int T; -int n; -char str[MAX_N][MAX_L]; -int len[MAX_N]; -int next[MAX_N][MAX_L]; - -char has_cal[MAX_N];//ǷѼ -char vis[MAX_N];//Ƿȸĸ - -int Index_KMP(int s, int t, int pos, int next[]){ -//±1ʼ[0] - int i=pos, j=1; - char* S = str[s]; - char* T = str[t]; - while(i<=len[s] && j<=len[t]){ - if(j==0 || S[i]==T[j]){i++; j++;} - else j=next[j]; - } - if(j>len[t]) return i-len[t]; - else return 0; -} - -void get_next(int t, int* next){ - int i=1, j=0; - char* T = str[t]; - int lt = len[t]; - next[0] = next[1] = 0; - while(i -using namespace std; - -int T; -int n, a, b; - -int gcd(int x, int y){ - if(y == 0) return x; - return gcd(y, x%y); -} - -void swap(int& x, int& y){ - int tmp = x; - x = y; - y = tmp; -} - -int main() -{ - freopen("5512.txt", "r", stdin); - scanf("%d", &T); - for(int ca=1; ca<=T; ca++){ - scanf("%d%d%d", &n, &a, &b); - if(a -#include -#include -using namespace std; - -const double eps = 1e-8; - -int cmp(double x){ - return x < -eps ? -1 : (x>eps); -} - -double pow2(double x){ - return x * x; -} - -double mySqrt(double x){ - return sqrt(max((double)0, x)); -} - -struct Vec -{ - double x, y; - Vec(){} - Vec(double xx, double yy):x(xx), y(yy){} - - Vec& operator=(const Vec& v){ - x = v.x; - y = v.y; - return *this; - } - - double norm(){ - return sqrt(pow2(x) + pow2(y)); - } - //返回单位向量 - Vec unit(){ - return Vec(x, y) / norm(); - } - //判等 - friend bool operator==(const Vec& v1, const Vec& v2){ - return cmp(v1.x - v2.x)==0 && cmp(v1.y - v2.y)==0; - } - - //+, -, 数乘 - friend Vec operator+(const Vec& v1, const Vec& v2){ - return Vec(v1.x + v2.x, v1.y + v2.y); - } - friend Vec operator-(const Vec& v1, const Vec& v2){ - return Vec(v1.x - v2.x, v1.y - v2.y); - } - friend Vec operator*(const Vec& v, const double c){ - return Vec(c*v.x, c*v.y); - } - friend Vec operator*(const double c, const Vec& v){ - return Vec(c*v.x, c*v.y); - } - friend Vec operator/(const Vec& v, const double c){ - return Vec(v.x/c, v.y/c); - } -}; - -int T; -int ans; -Vec O, A, V, B, C, B1; -int R; - -//点乘 -double dot(const Vec v1, const Vec v2){ - return v1.x*v2.x + v1.y*v2.y; -} -//叉乘的模长 -double product(const Vec v1, const Vec v2){ - return v1.x*v2.y - v1.y*v2.x; -} - -//点p到直线v1,v2的投影 -Vec project(Vec& v1, Vec& v2, Vec& p){ - Vec v = v2 - v1; - return v1 + v * dot(v, p-v1) / dot(v, v); -} -//点p关于直线v1,v2的对称点 -Vec mirrorPoint(Vec& v1, Vec& v2, Vec& p){ - Vec c = project(v1, v2, p); - //printf("project: %lf, %lf\n", c.x, c.y); - return (double)2*c - p; -} - -//判断点p是否在线段v1,v2上 -bool onSeg(Vec& v1, Vec& v2, Vec& p){ - if(cmp(product(p-v1, v2-v1))==0 && cmp(dot(p-v1, p-v2))<=0) - return true; - return false; -} - -bool calc_C(){ - //将AC表示为关于t的参数方程 - //则与圆的方程联立得到关于t的一元二次方程, a,b,c为一般式的三个系数 - double a = pow2(V.x) + pow2(V.y); - double b = 2*V.x*(A.x - O.x) + 2*V.y*(A.y - O.y); - double c = pow2(A.x - O.x) + pow2(A.y - O.y) - pow2(R); - double delta = pow2(b) - 4*a*c; - if(cmp(delta) <= 0) return false; - else{ - double t1 = (-b - mySqrt(delta))/(2*a); - double t2 = (-b + mySqrt(delta))/(2*a); - double t; - if(cmp(t1) >= 0) t = t1; - if(cmp(t2) >= 0 && t2 < t1) t = t2;//取较小的那个,即为离A近的那个交点 - C.x = A.x + V.x*t; - C.y = A.y + V.y*t; - return true; //有交点 - } -} - -int main() -{ - freopen("5572.txt", "r", stdin); - scanf("%d", &T); - for(int ca = 1; ca <= T; ca++){ - scanf("%lf%lf%d", &O.x, &O.y, &R); - scanf("%lf%lf%lf%lf", &A.x, &A.y, &V.x, &V.y); - scanf("%lf%lf", &B.x, &B.y); - if(calc_C()){ - if(onSeg(A, C, B)) ans = 1; - else{ - //printf("has intersection (%lf, %lf)\n", C.x, C.y); - Vec A1 = mirrorPoint(O, C, A); - // printf("A: %lf, %lf\n", A.x, A.y); - // printf("A1: %lf, %lf\n", A1.x, A1.y); - //printf("B1 (%lf, %lf)\n", B1.x, B1.y); - if(A==A1){ - Vec u = B - O; - Vec v = C - O; - // printf("OB: %lf %lf\n", u.unit().x, u.unit().y); - // printf("OC: %lf %lf\n", v.unit().x, v.unit().y); - if(u.unit() == v.unit()){ - ans = 1; - }else ans = 0; - }else { - Vec u = B - C; - Vec v = A1 - C; - if(u.unit() == v.unit()){ - ans = 1; - } - else ans = 0; - } - } - }else{//运动方向不变,则AB与V同向才可碰到B - //printf("no intersection\n"); - Vec temp = B - A; - if(temp.unit() == V.unit()) - ans = 1; - else ans = 0; - } - printf("Case #%d: %s\n", ca, ans ? "Yes" : "No"); - } - return 0; -} \ No newline at end of file diff --git a/Helena@ssglalw/hdu5572nzs.cpp b/Helena@ssglalw/hdu5572nzs.cpp deleted file mode 100644 index 26ce14d0..00000000 --- a/Helena@ssglalw/hdu5572nzs.cpp +++ /dev/null @@ -1,132 +0,0 @@ -//按照训练指南白书上模版写的新姿势,更好理解 -#include -#include -#include -using namespace std; - -const double eps = 1e-8; //1e-10会WA,注意调整精度,过大过小都不行 -int dcmp(double x){ - if(fabs(x) < eps) return 0; - return x < 0 ? -1 : 1; -} -double mySqrt(double x){ - return sqrt(max((double)0, x)); -} - -struct Point -{ - double x, y; - Point(double x=0, double y=0):x(x), y(y){} - Point& operator = (Point p){ - x = p.x; - y = p.y; - return *this; - } -}; - -typedef Point Vector; - -Vector operator + (Vector A, Vector B){ return Vector(A.x + B.x, A.y + B.y);} -Vector operator - (Point A, Point B){ return Vector(A.x - B.x, A.y - B.y);} -Vector operator * (Vector A, double p){ return Vector(A.x * p, A.y * p);} -Vector operator / (Vector A, double p){ return Vector(A.x / p, A.y / p);} - -double dot(Vector A, Vector B){ return A.x * B.x + A.y * B.y;} -double length(Vector A){ return mySqrt(dot(A, A));} -double cross(Vector A, Vector B){ return A.x * B.y - A.y * B.x;} - -struct Line -{ - Point p; - Vector v; - Line(Point p, Vector v):p(p), v(v){} - Point getPoint(double t){ - return Point(p.x + v.x*t, p.y + v.y*t); - } -}; - -struct Circle -{ - Point c; - double r; - Circle(Point c, double r):c(c), r(r){} -}; - -int getLineCircleIntersection(Line L, Circle C, Point& P){ //返回t较小的那个点 - double a = L.v.x; - double b = L.p.x - C.c.x; - double c = L.v.y; - double d = L.p.y - C.c.y; - - double e = a*a + c*c; - double f = 2*(a*b + c*d); - double g = b*b + d*d - C.r*C.r; - - double delta = f*f - 4*e*g; - - if(dcmp(delta) <= 0) return 0; - - double t = (-f - mySqrt(delta)) / (2*e); - P = L.getPoint(t); - return 1; -} - -bool onRay(Point A, Line L){//点A在射线L(p,v)上,不含端点 - Vector w = A - L.p; - if(dcmp(cross(w, L.v))==0 && dcmp(dot(w, L.v))>0) return true; - return false; -} - -bool onSeg(Point A, Point B, Point C){//点A在线段BC上 - return dcmp(cross(B-A, C-A))==0 && dcmp(dot(B-A, C-A))<0; -} - -Point project(Point A, Line L){ - return L.p + L.v * (dot(L.v, A - L.p)/dot(L.v, L.v)); -} -Point mirrorPoint(Point A, Line L){ - Vector D = project(A, L); - //printf("project: %lf, %lf\n", D.x, D.y); - return D + (D - A); -} - -int main() -{ - int T; - int ans = 0; - double R; - Point O, A, B; - Vector V; - freopen("5572.txt", "r", stdin); - scanf("%d", &T); - for(int ca = 1; ca <= T; ca++){ - scanf("%lf%lf%lf", &O.x, &O.y, &R); - scanf("%lf%lf%lf%lf", &A.x, &A.y, &V.x, &V.y); - scanf("%lf%lf", &B.x, &B.y); - Line LA = Line(A, V); - Circle yuanO = Circle(O, R); - Point C; - if(getLineCircleIntersection(LA, yuanO, C)){ - if(onSeg(B, A, C)) ans = 1; - else{ - Line OC = Line(O, Vector(C.x - O.x, C.y - O.y)); - Point A1 = mirrorPoint(A, OC); - // printf("%lf, %lf\n", C.x, C.y); - // printf("%lf, %lf\n", A1.x, A1.y); - Line CB = Line(C, Vector(B.x - C.x, B.y - C.y)); - - if(onRay(A1, CB)){ - ans = 1; - - } - else ans = 0; - } - }else{ - if(onRay(B, LA)) ans = 1; - else ans = 0; - } - printf("Case #%d: %s\n", ca, ans ? "Yes" : "No"); - } - - return 0; -} \ No newline at end of file diff --git a/Helena@ssglalw/hihocoder1255.cpp b/Helena@ssglalw/hihocoder1255.cpp deleted file mode 100644 index 2bdddef8..00000000 --- a/Helena@ssglalw/hihocoder1255.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -using namespace std; - -struct Rec{ - int w, h; - Rec& operator = (Rec& r){ - w = r.w; - h = r.h; - return *this; - } -}rec[4]; - -int n; -int index[4]; - -void swap(Rec& r){ //ע⴫ãֻβΡ - int temp = r.w; - r.w = r.h; - r.h = temp; -} - -void reverse(int x){ - for(int i=0; i<3; i++){ - if(x&1){ - swap(rec[index[i]]); - } - x >>= 1; - } -} - - -bool judge(){ - int ans = false; - - if(rec[index[0]].w == rec[index[1]].w - && rec[index[1]].w == rec[index[2]].w ) - ans = true; - else if(rec[index[1]].w == rec[index[2]].w - && rec[index[0]].h == rec[index[1]].h + rec[index[2]].h) - ans = true; - - return ans; -} - -int main() -{ - scanf("%d", &n); - while(n--){ - for(int i=0; i<4; i++){ - scanf("%d%d", &rec[i].w, &rec[i].h); - index[i] = i; - } - int flag = 0; - do{ - for(int i=0; i<8; i++){ - reverse(i); - if(judge()){ - flag = 1; - break; - } - reverse(i); - } - if(flag) break; - }while(next_permutation(index, index+4)); - printf("%s\n", flag ? "Yes" : "No"); - } - return 0; -} diff --git a/Helena@ssglalw/hihocoder1257.cpp b/Helena@ssglalw/hihocoder1257.cpp deleted file mode 100644 index 57fe112e..00000000 --- a/Helena@ssglalw/hihocoder1257.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -using namespace std; -int n; -int H, W; - -void printOdd(int x, int y){ - printf("%d %d ", x, y); -} - -void printEven(int x, int y){ - printf("%d %d ", x, y+H); -} - -int main(){ - while(~scanf("%d", &n)){ - H = (n+1)/2; - W = n&1 ? n : n+1; - printf("%d %d\n", H, W); - for(int i=1; i<=n; i++){ - if(i&1){ - int x = H, y = H - i/2; - while(x > y){ - printOdd(x, y); - x--; - } - printOdd(x, y); - y++; - while(y <= H){ - printOdd(x, y); - y++; - } - }else{ - if(n%4==0 || (n+1)%4==0){ - int len = i/2; - if(i%4 == 0){ - int x = H, y = i/2; - while(x > H - len + 1){ - printEven(x, y); - x--; - } - printEven(x, y); - y++; - while(x <= H){ - printEven(x, y); - x++; - } - }else { - int x = H - i/2 + 1, y = 1; - while(y < len){ - printEven(x, y); - y++; - } - printEven(x, y); - x--; - while(y >= 1){ - printEven(x, y); - y--; - } - } - }else{ - int len = i/2; - if(i%4 == 0){ - int x = H - i/2 + 1, y = 1; - while(y < len){ - printEven(x, y); - y++; - } - printEven(x, y); - x--; - while(y >= 1){ - printEven(x, y); - y--; - } - }else{ - int x = H, y = i/2; - while(x > H - len + 1){ - printEven(x, y); - x--; - } - printEven(x, y); - y++; - while(x <= H){ - printEven(x, y); - x++; - } - } - } - } - printf("\n"); - } - } - return 0; -} \ No newline at end of file diff --git a/Helena@ssglalw/hihocoder1258.cpp b/Helena@ssglalw/hihocoder1258.cpp deleted file mode 100644 index 2fffbbfb..00000000 --- a/Helena@ssglalw/hihocoder1258.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace std; - -int n; - -int main(){ - freopen("1258.txt", "r", stdin); - while(scanf("%d", &n)!=EOF){ - //printf("n: %d\n", n); - int cnt = 0; - getchar(); //吸收第一个n后的回车 - for(int i=0; i -#include -#include -using namespace std; -const int MAX_C = 100005; - -int heap[MAX_C]; - -void swap(int& a, int& b){ - int tmp = a; - a = b; - b = tmp; -} - -struct Heap -{ - int heap[MAX_C];//󶥶 - int size; - Heap(){size=0;} - void insert(int x){ - size++; - heap[size-1] = x; - int i = size - 1; - while(i > 0){ - int p = (i-1)/2; - if(heap[p] < heap[i]){ - swap(heap[p], heap[i]); - i = p; - }else break; - } - } - int getTop(){ - return heap[0]; - } - void deleteTop(){ - heap[0] = heap[size-1]; - size--; - int i = 0; - while(i*2+1 < size){ - int lc = i*2+1, rc=i*2+2; - int c = lc; - if(rcheap[lc]) - c = rc; - if(heap[c] > heap[i]){ - swap(heap[c], heap[i]); - i = c; - }else break; - } - } -}; - -struct Calf -{ - int score, aid; -}calves[MAX_C]; -bool cmp(Calf c1, Calf c2){ - return c1.score < c2.score; -} - -int N, C, F; -int before[MAX_C], after[MAX_C]; - -int main() -{ - freopen("2010.txt", "r", stdin); - scanf("%d%d%d", &N, &C, &F); - for(int i=0; iend; i--){ - ha.insert(calves[i].aid); - after[end] += calves[i].aid;//beginȻafter[C-begin] - } - //printf("after[%d] = %d\n", end, after[end]); - int flag = -1; - int sum = calves[end].aid + before[end] + after[end]; - if(sum <= F){ - printf("%d\n", calves[end].score); - return 0; - } - for(int i=end-1; i>=begin; i--){ //ʼӺǰöλi - if(calves[i+1].aid < ha.getTop()){ - after[i] = after[i+1] - ha.getTop() + calves[i+1].aid; - ha.deleteTop(); - ha.insert(calves[i+1].aid); - }else after[i] = after[i+1]; - //printf("after %d: %d\n", i, after[i]); - int sum = before[i] + after[i] + calves[i].aid; - //printf("sum %d: %d\n", i, sum); - if(sum <= F){ - flag = calves[i].score; - break; - } - } - printf("%d\n", flag); - return 0; -} diff --git a/Helena@ssglalw/poj2236.cpp b/Helena@ssglalw/poj2236.cpp deleted file mode 100644 index fcaab8f5..00000000 --- a/Helena@ssglalw/poj2236.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -using namespace std; -const int MAX_N = 1005; - -int parent[MAX_N]; - -void init(){ - memset(parent, -1, sizeof(parent)); -} -int find(int x){ - if(parent[x] == -1) - return x; - return parent[x] = find(parent[x]); -} -void unite(int x, int y){ - int rx = find(x); - int ry = find(y); - if(rx == ry) return ; //ע䣬ΪԷ-1ʾ - parent[ry] = rx; -} -bool same(int x, int y){ - return find(x) == find(y); -} - -struct Point -{ - double x, y; -}com[MAX_N]; - -double dis(Point p1, Point p2){ - return sqrt(pow(p1.x-p2.x, 2) + pow(p1.y-p2.y, 2)); -} - -int N, d; -double distance[MAX_N][MAX_N]; -bool repaired[MAX_N]; - -int main() -{ - freopen("2236.txt", "r", stdin); - memset(repaired, 0, sizeof(repaired)); - scanf("%d%d", &N, &d); - for(int i=1; i<=N; i++){ - scanf("%lf%lf", &com[i].x, &com[i].y); - } - - for(int i=1; i<=N; i++){ - for(int j=1; j -#include -using namespace std; -const int MAX_N = 10005; - -int heap[MAX_N];//󶥶 -int size; - -void push(int x){ - size++; - heap[size-1] = x; - int i = size-1; - while(i>0){ - int p = (i-1)>>1; - if(heap[p] >= x) break; - heap[i] = heap[p]; - i = p; - } - heap[i] = x; -} - -int pop(){ - int top = heap[0]; - heap[0] = heap[size-1]; - size--; - int x = heap[0]; - int i = 0; - while(i*2+1 < size){ - int lc = i*2+1; - int rc = i*2+2; - int c = lc; - if(rcheap[lc]) - c = rc; - if(heap[c] <= x) break; - heap[i] = heap[c]; - i = c; - } - heap[i] = x; - return top; -} - -struct Stop -{ - int dis, vol; -}stops[MAX_N]; - -bool cmp(Stop s1, Stop s2){ - return s1.dis < s2.dis; -} - -int n; -int L, P; - -int main() -{ - freopen("2431.txt", "r", stdin); - scanf("%d", &n); - for(int i=1; i<=n; i++){ - scanf("%d%d", &stops[i].dis, &stops[i].vol); - } - scanf("%d%d", &L, &P); - stops[0].dis = 0;//յtown - stops[n+1].dis = L;//㿴һվ - stops[n+1].vol = P; - - sort(stops, stops+n+1, cmp);// - - for(int i=n+1; i>=1; i--)//ijɴ浽һվľ - { - stops[i].dis -= stops[i-1].dis; - } - -// for(int i=0; i<=n+1; i++){ -// printf("%d %d\n", stops[i].dis, stops[i].vol); -// } - - int cur_vol = 0; - int cnt = -1; - for(int i=n+1; i>=1; i--){ - push(stops[i].vol); - cur_vol -= stops[i].dis; - if(cur_vol < 0){ - int flag = 0; - while(size>0){ - cur_vol += heap[0]; - pop(); - cnt++; - if(cur_vol >= 0){ - flag = 1; - break; - } - } - if(!flag){ - printf("-1\n"); - return 0; - } - } - } - printf("%d\n", cnt); - return 0; -} diff --git a/Helena@ssglalw/poj3614.cpp b/Helena@ssglalw/poj3614.cpp deleted file mode 100644 index 875f67e6..00000000 --- a/Helena@ssglalw/poj3614.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -using namespace std; -const int MAX_C = 2505; -const int MAX_L = 2505; -int C, L; -struct Cow -{ - int min, max; - Cow& operator = (Cow& c){ - min = c.min; - max = c.max; - return *this; - } -}cows[MAX_C]; - -struct Lotion -{ - int spf,cover; -}lotions[MAX_C]; - -bool cmpL(Lotion l1, Lotion l2){ - return l1.spf < l2.spf; -} -bool cmpC(Cow c1, Cow c2){ - return c1.min < c2.min; -} - -int heap[MAX_C]; //小顶堆 -int size = 0; - -void insert(int x){ - size++; - heap[size-1] = x;//目标元素暂时插到末尾 - int i = size - 1;//候选目标位置 - while(i > 0){//上滤,反复与父节点比较 - int p = (i-1)/2;//比较候选位置的父节点和目标元素 - if(heap[p] > x){ - heap[i] = heap[p];//父节点下沉 - i = p;//候选位置上升 - }else break; - } - heap[i] = x; -} - -void deleteTop(){ - heap[0] = heap[size-1]; - size--; - int x = heap[0]; //把末尾元素提到堆顶 - int i = 0; //候选目标位置 - while(i*2+1 < size){//下滤 - int lc = i*2+1; - int rc = i*2+2; - int c = lc; - if(rc 0 && size>0){ - if(getTop() >= lotions[i].spf){ - vol--; - cnt++; - //printf("add %d\n", getTop()); - } - deleteTop(); - //printf("%d\n", cnt); - } - } - printf("%d\n", cnt); - return 0; -} diff --git a/Kirai/16_05_05_UVALive_7261.cpp b/Kirai/16_05_05_UVALive_7261.cpp deleted file mode 100644 index fc7e5b1b..00000000 --- a/Kirai/16_05_05_UVALive_7261.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef long long ll; -typedef struct Node { - ll x, y; - ll a, b; -}Node; -const int maxn = 1000010; -ll r, n; -int pos; -Node sq[maxn]; -ll sum[maxn]; -ll tot; - -int main() { - // freopen("in", "r", stdin); - int T; - scanf("%d", &T); - while(T--) { - scanf("%I64d %I64d", &r, &n); - tot = 0; - memset(sum, 0, sizeof(sum)); - memset(sq, 0, sizeof(sq)); - for(int i = 0; i < n; i++) { - scanf("%I64d%I64d%I64d%I64d", &sq[i].x, &sq[i].y, &sq[i].a, &sq[i].b); - tot += sq[i].a * sq[i].b; - for(int j = sq[i].x; j < sq[i].x + sq[i].a; j++) { - sum[j] += sq[i].b; - } - } - ll cur = 0; - for(pos = 0; cur * 2 < tot; pos++) { - cur += sum[pos]; - } - while(0 == sum[pos] && pos < r) pos++; - printf("%d\n", pos); - } - return 0; -} diff --git a/Kirai/16_05_06_51NOD_1051.cpp b/Kirai/16_05_06_51NOD_1051.cpp deleted file mode 100644 index 5cfc4295..00000000 --- a/Kirai/16_05_06_51NOD_1051.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef long long ll; -const int maxn = 501; -const ll inf = 0x7f7f7f7f; -ll n, m; -ll G[maxn][maxn]; -ll dp[maxn]; - -ll lss() { - ll ans = -inf, tmp = -inf; - for(int i = 0; i < m; i++) { - if(tmp > 0) tmp += dp[i]; - else tmp = dp[i]; - ans = max(ans, tmp); - } - return ans; -} - -inline bool scan_d(ll &num) { - char in;bool IsN=false; - in=getchar(); - if(in==EOF) return false; - while(in!='-'&&(in<'0'||in>'9')) in=getchar(); - if(in=='-'){ IsN=true;num=0;} - else num=in-'0'; - while(in=getchar(),in>='0'&&in<='9'){ - num*=10,num+=in-'0'; - } - if(IsN) num=-num; - return true; -} - -int main() { - // freopen("in", "r", stdin); - scan_d(m); scan_d(n); - for(int i = 0; i < n; i++) { - for(int j = 0; j < m; j++) { - scan_d(G[i][j]); - } - } - ll ans = -inf; - for(int i1 = 0; i1 < n; i1++) { - memset(dp, 0, sizeof(dp)); - for(int i = i1; i < n; i++) { - for(int j = 0; j < m; j++) { - dp[j] += G[i][j]; - } - ll tmp = lss(); - ans = max(tmp, ans); - } - } - printf("%I64d\n", ans < 0 ? 0 : ans); - return 0; -} diff --git a/Kirai/16_05_06_HIHO_1299.cpp b/Kirai/16_05_06_HIHO_1299.cpp deleted file mode 100644 index 887c0f23..00000000 --- a/Kirai/16_05_06_HIHO_1299.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -//kirai²»ÊÇɳ²è£¬²»»áÍü¼ÇÐÞ¸Ämaxn -#define lson l, m, rt << 1 -#define rson m + 1, r, rt << 1 | 1 -typedef long long ll; -typedef struct Node { - int t, v; -}Node; -const int maxn = 100010; -int n, m; -int sum[maxn<<2]; - -void pushUP(int rt) { - //modify - sum[rt] = max(sum[rt<<1], sum[rt<<1|1]); -} - -void build(int l, int r, int rt) { - if(l == r) { - sum[rt] = -1; - return; - } - int m = (l + r) >> 1; - build(lson); - build(rson); - pushUP(rt); -} - -void update(int p, int add, int l, int r, int rt) { - if(l == r) { - sum[rt] = max(sum[rt], add); - return; - } - int m = (l + r) >> 1; - if(p <= m) { - update(p, add, lson); - } - else { - update(p, add, rson); - } - pushUP(rt); -} - -int query(int L, int R, int l, int r, int rt) { - if(L <= l && r <= R) { - return sum[rt]; - } - int m = (l + r) >> 1; - int ret = 0; - if(L <= m) { - //modify - ret = max(ret, query(L, R, lson)); - } - if(R > m) { - //modify - ret = max(ret, query(L, R, rson)); - } - return ret; -} - -int main() { - // freopen("in", "r", stdin); - while(~scanf("%d%d", &n, &m)) { - int t, v; - build(1, n, 1); - for(int i = 0; i < n; i++) { - scanf("%d%d", &t, &v); - update(t, v, 1, n, 1); - } - int a, b; - while(m--) { - scanf("%d%d", &a, &b); - int ans = query(a, b, 1, n, 1); - if(ans <= 0) printf("None\n"); - else printf("%d\n", ans); - } - } - return 0; -} diff --git a/Kirai/16_05_07_HIHO_1260.cpp b/Kirai/16_05_07_HIHO_1260.cpp deleted file mode 100644 index 481c6330..00000000 --- a/Kirai/16_05_07_HIHO_1260.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef struct Node { - Node *next[26]; - int cnt; - Node() { - cnt = 0; - for(int i = 0; i < 26; i++) { - next[i] = NULL; - } - } -}Node; - -void insert(Node *p, char *str) { - for(int i = 0; str[i]; i++) { - int t = str[i] - 'a'; - if(p->next[t] == NULL) { - p->next[t] = new Node(); - } - p = p->next[t]; - } - p->cnt++; -} - -int len, cnt; - -void dfs(Node *p, char *str, int cur, int flag) { - if(flag > 1) return; - if(cur == len && flag == 1) { - cnt++; - return; - } - for(int i = 0; i < 26; i++) { - if(p->next[i]) { - if('a' + i == str[cur]) { - dfs(p->next[i], str, cur+1, flag); - } - else { - if(flag > 1) continue; - dfs(p->next[i], str, cur, flag+1); - } - } - } -} - -void del(Node *root) { - for(int i = 0; i < 26; i++) { - if(root->next[i] != NULL) { - del(root->next[i]); - } - } - delete root; -} - -const int maxn = 100010; -int n, m; -char tmp[maxn]; - -int main() { - // freopen("in", "r", stdin); - while(~scanf("%d %d", &n, &m)) { - Node *root = new Node(); - for(int i = 0; i < n; i++) { - scanf("%s", tmp); - insert(root, tmp); - } - for(int i = 0; i < m; i++) { - scanf("%s", tmp); - len = strlen(tmp); - cnt = 0; - dfs(root, tmp, 0, 0); - printf("%d\n", cnt); - } - } - return 0; -} diff --git a/Kirai/16_05_08_QLCODER_7560.py b/Kirai/16_05_08_QLCODER_7560.py deleted file mode 100644 index 218a71ee..00000000 --- a/Kirai/16_05_08_QLCODER_7560.py +++ /dev/null @@ -1,43 +0,0 @@ -import re -import urllib - -wtf = 'https://movie.douban.com/top250?start=00&filter=' -urls = [] -scores = [] - -def calURL(): - step = 0 - while step <= 166: - tmp = wtf[:38] - tmp += str(step) - tmp += wtf[40:] - urls.append(tmp) - step += 25 - -def getHTML(url): - page = urllib.urlopen(url) - html = page.read() - return html - -def getScore(html): - score = [] - reg = r'property="v:average">([0-9].[0-9])' - score = re.findall(re.compile(reg), html) - return score - -def solve(): - calURL() - for each in urls: - print each - scores.append(getScore(getHTML(each))) - sum = 0 - cnt = 0 - for each in scores: - if cnt == 166: break - for i in range(0, len(each)): - if cnt == 166: break - cnt += 1 - sum += float(each[i]) - return sum - -print solve() diff --git a/Kirai/16_05_09_HDOJ_2830.cpp b/Kirai/16_05_09_HDOJ_2830.cpp deleted file mode 100644 index eaa6a739..00000000 --- a/Kirai/16_05_09_HDOJ_2830.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%lld", &a) -#define Rs(a) scanf("%s", a) -#define FRead() freopen("in", "r", stdin) -#define Rep(i, n) for(int i = 0; i < (n); i++) -#define For(i, a, n) for(int i = (a); i < (n); i++) -#define Cls(a) memset((a), 0, sizeof(a)) -const int maxn = 1010; - -int n, m; -int h[maxn]; -int dp[maxn]; -char G[maxn][maxn]; - -int main() { - // FRead(); - while(~Rint(n) && ~Rint(m)) { - int ans = 0; - Cls(h); Cls(dp); - Rep(i, n) Rs(G[i]); - Rep(i, n) { - Rep(j, m) { - if(G[i][j] == '1') h[j]++; - else h[j] = 0; - dp[j] = h[j]; - } - sort(dp, dp+m, greater()); - Rep(j, m) { - if(dp[j] == 0) break; - ans = max(ans, dp[j] * (j + 1)); - } - } - printf("%d\n", ans); - } - return 0; -} diff --git a/Kirai/16_05_10_AStar2015_1002.cpp b/Kirai/16_05_10_AStar2015_1002.cpp deleted file mode 100644 index 7c038aa9..00000000 --- a/Kirai/16_05_10_AStar2015_1002.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%I64d", &a) -#define Rs(a) scanf("%s", a) -#define FRead() freopen("in", "r", stdin) -#define FWrite() freopen("out", "w", stdout) -#define Rep(i, n) for(int i = 0; i < (n); i++) -#define For(i, a, n) for(int i = (a); i < (n); i++) -#define Cls(a) memset((a), 0, sizeof(a)) -#define Full(a) memset((a), 0x7f7f, sizeof(a)) - -const int maxn = 1000010; -int k, cnt; -char pos[maxn]; -char s[maxn]; - -int main() { - // FRead(); - int T, _ = 1; - Rint(T); - while(T--) { - Cls(s); Cls(pos);; - getchar(); gets(s); Rint(k); - int n = strlen(s); cnt = 0; - int p = n % k; - int r = n / k + 1; - Rep(i, p) { - Rep(j, r) { - pos[i+k*j] = s[cnt++]; - } - } - For(i, p, k) { - Rep(j, r-1) { - pos[i+k*j] = s[cnt++]; - } - } - printf("Case #%d:\n", _++); - printf("%s\n", pos); - } - return 0; -} diff --git a/Kirai/16_05_11_POJ_2104.cpp b/Kirai/16_05_11_POJ_2104.cpp deleted file mode 100644 index 30365db7..00000000 --- a/Kirai/16_05_11_POJ_2104.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define pb(a) push_back(a) -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%I64d", &a) -#define Rs(a) scanf("%s", a) -#define FRead() freopen("in", "r", stdin) -#define FWrite() freopen("out", "w", stdout) -#define Rep(i, n) for(int i = 0; i < (n); i++) -#define For(i, a, n) for(int i = (a); i < (n); i++) -#define Cls(a) memset((a), 0, sizeof(a)) -#define Full(a) memset((a), 0x7f7f, sizeof(a)) - -const int maxn = 1000010; -int n, m; -int cnt, root[maxn], a[maxn], x, y, k; -typedef struct Node { - int l, r, sum; -}Node; -vector v; -Node hjt[maxn*40]; - -int getid(int x) { - return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; -} - -void update(int l, int r, int& x, int y, int pos) { - hjt[++cnt] = hjt[y], hjt[cnt].sum++, x = cnt; - if(l == r) return; - int mid = (l + r) >> 1; - if(mid >= pos) update(l, mid, hjt[x].l, hjt[y].l, pos); - else update(mid+1, r, hjt[x].r, hjt[y].r, pos); -} - -int query(int l, int r, int x, int y, int k) { - if(l == r) return l; - int mid = (l + r) >> 1; - int sum = hjt[hjt[y].l].sum - hjt[hjt[x].l].sum; - if(sum >= k) return query(l, mid, hjt[x].l, hjt[y].l, k); - else return query(mid+1, r, hjt[x].r, hjt[y].r, k-sum); -} - -int main() { - // FRead(); - Rint(n); Rint(m); - For(i, 1, n+1) { - Rint(a[i]); - v.pb(a[i]); - } - sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end()); - For(i, 1, n+1) update(1, n, root[i], root[i-1], getid(a[i])); - For(i, 1, m+1) { - Rint(x), Rint(y), Rint(k); - printf("%d\n", v[query(1, n, root[x-1], root[y], k)-1]); - } - return 0; -} diff --git a/Kirai/16_05_12_HDOJ_4022.cpp b/Kirai/16_05_12_HDOJ_4022.cpp deleted file mode 100644 index 97384894..00000000 --- a/Kirai/16_05_12_HDOJ_4022.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define pb(a) push_back(a) -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%I64d", &a) -#define Rs(a) scanf("%s", a) -#define FRead() freopen("in", "r", stdin) -#define FWrite() freopen("out", "w", stdout) -#define Rep(i, n) for(int i = 0; i < (n); i++) -#define For(i, a, n) for(int i = (a); i < (n); i++) -#define Cls(a) memset((a), 0, sizeof(a)) -#define Full(a) memset((a), 0x7f7f, sizeof(a)) - -const int maxn = 100010; -int n, m; -int x[maxn], y[maxn]; -int hx[maxn], hxcnt; -int hy[maxn], hycnt; -int sx[maxn], sy[maxn]; -map > xx; -map > yy; -multiset::iterator it; - -inline bool scan_d(int &num) { - char in;bool IsN=false; - in=getchar(); - if(in==EOF) return false; - while(in!='-'&&(in<'0'||in>'9')) in=getchar(); - if(in=='-'){ IsN=true;num=0;} - else num=in-'0'; - while(in=getchar(),in>='0'&&in<='9'){ - num*=10,num+=in-'0'; - } - if(IsN) num=-num; - return true; -} - -int getid(int* h, int hcnt, int x) { - return lower_bound(h, h+hcnt, x) - h; -} - -int main() { - // FRead(); - int c, d; - while(~scanf("%d%d", &n, &m) && n + m) { - Cls(sx); Cls(sy); xx.clear(), yy.clear(); - Rep(i, n) { - scan_d(x[i]); scan_d(y[i]); - hx[i] = x[i]; hy[i] = y[i]; - xx[x[i]].insert(y[i]); - yy[y[i]].insert(x[i]); - } - sort(hx, hx+n); sort(hy, hy+n); - hxcnt = unique(hx, hx+n) - hx; - hycnt = unique(hy, hy+n) - hy; - Rep(i, n) { - sx[getid(hx, hxcnt, x[i])]++; - sy[getid(hy, hycnt, y[i])]++; - } - Rep(i, m) { - scan_d(c); scan_d(d); - if(c == 0) { - printf("%d\n", xx[d].size()); - for(it = xx[d].begin(); it != xx[d].end(); it++) { - yy[*it].erase(d); - } - xx[d].clear(); - sx[getid(hx, hxcnt, d)] = 0; - } - else { - printf("%d\n", yy[d].size()); - for(it = yy[d].begin(); it != yy[d].end(); it++) { - xx[*it].erase(d); - } - sy[getid(hy, hycnt, d)] = 0; - yy[d].clear(); - } - } - printf("\n"); - - } - return 0; -} diff --git a/Kirai/16_05_13_HIHO_1077.cpp b/Kirai/16_05_13_HIHO_1077.cpp deleted file mode 100644 index 902fd946..00000000 --- a/Kirai/16_05_13_HIHO_1077.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define pb(a) push_back(a) -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%I64d", &a) -#define Rs(a) scanf("%s", a) -#define FRead() freopen("in", "r", stdin) -#define FWrite() freopen("out", "w", stdout) -#define Rep(i, n) for(int i = 0; i < (n); i++) -#define For(i, a, n) for(int i = (a); i < (n); i++) -#define Cls(a) memset((a), 0, sizeof(a)) -#define Full(a) memset((a), 0x7f7f, sizeof(a)) - -#define lrt rt << 1 -#define rrt rt << 1 | 1 -const int maxn = 10000010; -int sum[maxn<<1]; -int n, m; - -void pushUP(int rt) { - sum[rt] = min(sum[lrt], sum[rrt]); -} - -void build(int l, int r, int rt) { - if(l == r) { - Rint(sum[rt]); - return; - } - int m = (l + r) >> 1; - build(l, m, lrt); - build(m+1, r, rrt); - pushUP(rt); -} - -void update(int p, int x, int l, int r, int rt) { - if(l == r) { - sum[rt] = x; - return; - } - int m = (l + r) >> 1; - if(p <= m) update(p, x, l, m, lrt); - else update(p, x, m+1, r, rrt); - pushUP(rt); -} - -int query(int L, int R, int l, int r, int rt) { - if(L <= l && r <= R) return sum[rt]; - int m = (l + r) >> 1; - int ret = 0x7f7f7f; - if(m >= L) ret = min(ret, query(L, R, l, m, lrt)); - if(m < R) ret = min(ret, query(L, R, m+1, r, rrt)); - return ret; -} - -int main() { - // FRead(); - int a, b, c; - while(~Rint(n)) { - build(1, n, 1); - Rint(m); - while(m--) { - Rint(c); Rint(a); Rint(b); - if(c == 0) printf("%d\n", query(a, b, 1, n, 1)); - else update(a, b, 1, n, 1); - } - } - return 0; -} diff --git a/Kirai/16_05_14_ZOJ_1610.cpp b/Kirai/16_05_14_ZOJ_1610.cpp deleted file mode 100644 index a052079e..00000000 --- a/Kirai/16_05_14_ZOJ_1610.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define pb(a) push_back(a) -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%I64d", &a) -#define Rs(a) scanf("%s", a) -#define Fread() freopen("in", "r", stdin) -#define Fwrite() freopen("out", "w", stdout) -#define Rep(i, n) for(int i = 0; i < (n); i++) -#define For(i, a, n) for(int i = (a); i < (n); i++) -#define Cls(a) memset((a), (0), sizeof(a)) -#define Clr(a, x) memset((a), (x), sizeof(a)) -#define Full(a) memset((a), 0x7f7f, sizeof(a)) - -#define lson l, m, rt << 1 -#define rson m + 1, r, rt << 1 | 1 -const int maxn = 8010; -int sum[maxn<<2]; -int vis[maxn]; -int n, a, b, c; - -void pushDOWN(int rt) { - if(sum[rt] != -1) { - sum[rt<<1] = sum[rt<<1|1] = sum[rt]; - sum[rt] = -1; - } -} - -void update(int L, int R, int c, int l, int r, int rt) { - if(L <= l && r <= R) { - sum[rt] = c; - return; - } - pushDOWN(rt); - int m = (l + r) >> 1; - if(L <= m) update(L, R, c, lson); - if(R > m) update(L, R, c, rson); -} - -int query(int p, int l, int r, int rt) { - if(l == r) { - return sum[rt]; - } - pushDOWN(rt); - int m = (l + r) >> 1; - if(p <= m) return query(p, lson); - else return query(p, rson); -} - -int main() { - // Fread(); - while(~Rint(n)) { - int lo = 0x7f7f; - Clr(sum, -1); Cls(vis); - Rep(i, n) { - Rint(a), Rint(b), Rint(c); - lo = min(lo, a+1); - update(a+1, b, c, 1, 8000, 1); - } - int p = query(lo, 1, 8000, 1); - vis[p]++; - For(i, lo+1, 8001) { - int t = query(i, 1, 8000, 1); - if(t == -1) { - p = -1; - continue; - } - if(t != p) { - vis[t]++; - p = t; - } - - } - Rep(i, 8001) { - if(vis[i]) printf("%d %d\n", i, vis[i]); - } - printf("\n"); - } - return 0; -} diff --git a/Kirai/16_05_15_POJ_3264.cpp b/Kirai/16_05_15_POJ_3264.cpp deleted file mode 100644 index 1e987722..00000000 --- a/Kirai/16_05_15_POJ_3264.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define fr first -#define sc second -#define pb(a) push_back(a) -#define Rint(a) scanf("%d", &a) -#define Rll(a) scanf("%I64d", &a) -#define Rs(a) scanf("%s", a) -#define FRead() freopen("in", "r", stdin) -#define FWrite() freopen("out", "w", stdout) -#define Rep(i, len) for(int i = 0; i < (len); i++) -#define For(i, a, len) for(int i = (a); i < (len); i++) -#define Cls(a) memset((a), 0, sizeof(a)) -#define Full(a) memset((a), 0x7f7f, sizeof(a)) - -typedef struct Node { - int lo, hi; - Node() {} - Node(int l, int h) : lo(l), hi(h) {} -}Node; - -#define lrt rt << 1 -#define rrt rt << 1 | 1 -const int maxn = 500010; -Node h[maxn<<1]; -int n, q; - -void pushUP(int rt) { - h[rt].lo = min(h[lrt].lo, h[rrt].lo); - h[rt].hi = max(h[lrt].hi, h[rrt].hi); -} - -void build(int l, int r, int rt) { - if(l == r) { - Rint(h[rt].lo); - h[rt].hi = h[rt].lo; - return; - } - int m = (l + r) >> 1; - build(l, m, lrt); - build(m+1, r, rrt); - pushUP(rt); -} - -Node query(int L, int R, int l, int r, int rt) { - if(L <= l && r <= R) return h[rt]; - int m = (l + r) >> 1; - Node ret(0x7f7f7f, 0), tmp; - if(m >= L) { - tmp = query(L, R, l, m, lrt); - ret.lo = min(ret.lo, tmp.lo); - ret.hi = max(ret.hi, tmp.hi); - } - if(m < R) { - tmp = query(L, R, m+1, r, rrt); - ret.lo = min(ret.lo, tmp.lo); - ret.hi = max(ret.hi, tmp.hi); - } - return ret; -} - -int main() { - // FRead(); - int a, b; - while(~Rint(n) && ~Rint(q)) { - build(1, n, 1); - while(q--) { - Rint(a); Rint(b); - Node ret = query(a, b, 1, n, 1); - printf("%d\n", ret.hi - ret.lo); - } - } - return 0; -} diff --git a/Kirai/README.md b/Kirai/README.md deleted file mode 100644 index aefca5d6..00000000 --- a/Kirai/README.md +++ /dev/null @@ -1 +0,0 @@ -# Kirai的博客:http://www.cnblogs.com/VincentX/ \ No newline at end of file diff --git a/LBCross/2016_05_08.cpp b/LBCross/2016_05_08.cpp deleted file mode 100644 index 18859ea7..00000000 --- a/LBCross/2016_05_08.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 1000100 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -#define INF (1ll<<60)-1 -using namespace std; -int vis[200100],n,k; -struct node{ - int x,step; - node(int x=0,int step=0):x(x),step(step){} -}; -void bfs(){ - mst(vis,0); - queue qu; - qu.push(node(n,0)); - vis[n]=1; - while(!qu.empty()){ - node now=qu.front(); - qu.pop(); - if(!vis[now.x+1] && now.x+1<100001){ - if(now.x+1==k) { - cout<=0){ - if(now.x-1==k) { - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 1000100 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -#define INF (1ll<<60)-1 -using namespace std; -int mu[1000100],prime[1000100],vis[1000100],a[1000100]; -struct node{ - int v,step; - node(int v=0,int step=0):v(v),step(step){} -}; -int used[1000100]; -void BFS(int x,int y){ - mst(used,0); - queue qu; - qu.push(node(x,0)); - used[x]=1; - while(!qu.empty()){ - node now=qu.front(); - qu.pop(); - if(now.v==y){ - cout<=1000 && i<10000) a[num++]=i; - } - for(int j=0;j100000) break; - vis[i*prime[j]]=1; - if(i%prime[j]==0){ - mu[i*prime[j]]=0; - break; - } else mu[i*prime[j]]=-mu[i]; - } - } - mst(vis,0); - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 10000005 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -using namespace std; -const ll INF=1e14+5; -#define mod 1000000007 -int T,cas; -vector< pair > V; -vector anw; -int vis[MAX],prime[MAX]; -void init(){ - int cnt=0; - V.push_back(make_pair(1LL,1)); - for(int i=2;i<=MAX;i++){ - if(!vis[i]){ - prime[cnt++]=i; - for(double j=(double)i*i;jMAX) break; - vis[i*prime[j]]=1; - if(i%prime[j]==0) break; - } - } - sort(V.begin(),V.end()); - anw.push_back(1LL); - for(int i=1;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 1000100 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -#define INF (1ll<<60)-1 -using namespace std; -int a[10][10]; -struct node{ - int x,y,pre; - node(){} - node (int x,int y):x(x),y(y){} -}; -int xx[4]={0,1,0,-1}; -int yy[4]={1,0,-1,0}; -bool pd(node t){ - if(a[t.x][t.y]==1 || t.x<1 || t.x>5 || t.y<1 || t.y>5) - return false; - return true; -} -int anw[10][10]; -void print(int pre){ - if(pre>0){ - int x,y; - if(pre%5==0) x=pre/5; - else x=pre/5+1; - y=pre%5; - if(y==0) y=5; - print(anw[x][y]); - printf("(%d, %d)\n",x-1,y-1); - } -} -void BFS(node S){ - mst(anw,0); - queue qu; - qu.push(S); - a[S.x][S.y]=1; - anw[S.x][S.y]=0; - while(!qu.empty()){ - node now=qu.front(),next; - qu.pop(); - for(int i=0;i<4;i++){ - next.x=now.x+xx[i]; - next.y=now.y+yy[i]; - if(pd(next)){ - a[next.x][next.y]=1; - next.pre=(now.x-1)*5+now.y; - anw[next.x][next.y]=next.pre; - ///printf("%d %d %d\n",next.x,next.y,next.pre); - if(next.x==5 && next.y==5){ - print(next.pre); - return ; - } - qu.push(next); - } - } - } -} -int main(){ - int x; - while(scanf("%d",&x)!=EOF){ - mst(a,0); - a[1][1]=x; - for(int i=1;i<=5;i++){ - for(int j=1;j<=5;j++){ - if(i==1 && j==1) continue; - scanf("%d",&a[i][j]); - } - } - node S=node(1,1); - BFS(S); - printf("(4, 4)\n"); - } - return 0; -} diff --git a/LBCross/2016_05_12 cf352 div2 C.cpp b/LBCross/2016_05_12 cf352 div2 C.cpp deleted file mode 100644 index 6d2fd2fc..00000000 --- a/LBCross/2016_05_12 cf352 div2 C.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 1000100 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -#define INF (1ll<<60)-1 -using namespace std; -struct point{ - long double x,y,dis; - int id; -}s[100100],p[100100]; -int vis[100100]; -const long double eps=1e-8; -int dcmp(long double x){ - if(fabs(x)<=eps) return 0; - return x<0?-1:1; -} -long double disn(point a,point b){ - return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); -} -bool cmp(point a,point b){ - return dcmp(a.dis-b.dis)>0; -} -int n; -int main(){ - point A,B,C; - cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y; - scanf("%d",&n); - for(int i=1;i<=n;i++) cin>>s[i].x>>s[i].y; - long double ans1=0,ans2=0,ans3=0,mx1=-INF*1.0,mx2=mx1,ans=0,mx_1=mx1,mx_2=mx1; - for(int i=1;i<=n;i++) ans+=disn(s[i],C)*2; - int tmp1=-1,tmp2=-1; - for(int i=1;i<=n;i++){ - long double d1=disn(A,s[i]); - long double d2=disn(C,s[i]); - long double d3=d2-d1; - if(dcmp(d3-mx1)>=0){ - if(dcmp(mx1-mx_1)>=0) mx_1=mx1; - mx1=d3; - tmp1=i; - } else if(dcmp(d3-mx_1)>=0){ - mx_1=d3; - } - } - ans1=ans-mx1; - for(int i=1;i<=n;i++){ - long double d1=disn(B,s[i]); - long double d2=disn(C,s[i]); - long double d3=d2-d1; - if(dcmp(d3-mx2)>=0){ - if(dcmp(mx2-mx_2)>=0) mx_2=mx2; - mx2=d3; - tmp2=i; - } else if(dcmp(d3-mx_2)>=0){ - mx_2=d3; - } - } - ans2=ans-mx2; - /*cout<=0){ - ans3=ans-mx1-mx_2; - } else ans3=ans-mx_1-mx2; - } - long double anw=INF*1.0; - anw=min(anw,ans1); - anw=min(anw,ans2); - anw=min(anw,ans3); - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 1000100 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -#define INF (1ll<<60)-1 -using namespace std; -int n,k; -int a[500100]; -ll solve1(int x){ - ll ans=0; - for(int i=1;i<=n;i++){ - if(a[i]x) ans+=1LL*(a[i]-x); - } - return ans; -} -int main(){ - scanf("%d%d",&n,&k); - ll sum=0; - for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i]; - int l=1,r=1e9,mid,ans1=1,ans2=1; - while(l0) cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define mst(ss,b) memset((ss),(b),sizeof(ss)) -#define maxn 0x3f3f3f3f -#define MAX 1000100 -///#pragma comment(linker, "/STACK:102400000,102400000") -typedef long long ll; -typedef unsigned long long ull; -#define INF (1ll<<60)-1 -using namespace std; -int n,m,now; -char s[500100],p[500100]; -stack sta; -int a[500100]; -struct node{ - int l,r; -}L[500100]; -int main(){ - scanf("%d%d%d%s%s",&n,&m,&now,s+1,p+1); - for(int i=1;i<=n;i++){ - if(s[i]=='(') sta.push(i); - else { - a[i]=sta.top(); - a[sta.top()]=i; - sta.pop(); - } - } - for(int i=1;i<=n;i++){ - L[i].l=i-1; - L[i].r=i+1; - } - L[n].r=0; - for(int i=1;i<=m;i++){ - if(p[i]=='R') now=L[now].r; - else if(p[i]=='L') now=L[now].l; - else { - if(s[now]=='('){ - int x=now; - int y=a[now]; - now=L[y].r; - if(now==0) now=L[x].l; - L[L[x].l].r=L[y].r; - L[L[y].r].l=L[x].l; - } else { - int x=a[now]; - int y=now; - now=L[y].r; - if(now==0) now=L[x].l; - L[L[x].l].r=L[y].r; - L[L[y].r].l=L[x].l; - } - } - } - ///for(int i=1;i<=n;i++) cout<=0: - min_num = min(min_num, dp[i-j]) - dp[i] = min_num+1 - return dp[amount]==amount+1 and -1 or dp[amount] diff --git a/Manjuska/leetcode179.py b/Manjuska/leetcode179.py deleted file mode 100644 index 3cdfef32..00000000 --- a/Manjuska/leetcode179.py +++ /dev/null @@ -1,11 +0,0 @@ - -class Solution: - # @param {integer[]} nums - # @return {string} - @classmethod - - def largestNumber(self, nums): - ret = ''.join(sorted([str(x) for x in nums],cmp=lambda x,y:cmp(y+x,x+y))) - return ret if ret[0] !='0' else "0" - - diff --git a/Manjuska/leetcode230.py b/Manjuska/leetcode230.py deleted file mode 100644 index 894ff533..00000000 --- a/Manjuska/leetcode230.py +++ /dev/null @@ -1,36 +0,0 @@ -def maximalSquare(matrix): - """ - :type matrix: List[List[str]] - :rtype: int - """ - if matrix is None or len(matrix) == 0 or len(matrix[0]) == 0: - return 0 - n = len(matrix) - m = len(matrix[0]) - d = [[0] * n] * m - Max = 0 - for i in range(0, m): - if matrix[i][0] == '1': - d[i][0] = 1 - Max = 1 - for j in range(0, n): - if matrix[0][j] == '1': - d[0][j] = 1 - #print(d[1]) - Max = 1 - - print(d) - for i in range(1, m): - for j in range(1, n): - #print(i,j) - #print(matrix[i][j]) - - if (matrix[i][j] == '1'): - #d[i][j] = 0 - d[i][j] = min(d[i - 1][j], d[i][j - 1], d[i - 1][j - 1]) + 1 - - Max = max(Max, d[i][j]) - #print(d) - return Max * Max -if __name__ == '__main__': - print(maximalSquare(["1010","1011","1011","1111"])) \ No newline at end of file diff --git a/Manjuska/leetcode300.py b/Manjuska/leetcode300.py deleted file mode 100644 index 063bde14..00000000 --- a/Manjuska/leetcode300.py +++ /dev/null @@ -1,38 +0,0 @@ -# encoding: utf-8 -""" -@version: ?? -@author: Jeff -@contact: lizheao940510@gmail.com -@software: PyCharm -@file: leetcode300.py -@time: 21:03 -""" - - -def lengthOfLIS(nums): - """ - :type nums: List[int] - :rtype: int - """ - if nums == None or len(nums) < 1: - return 0 - dp=[] - dp=[] - dp.append(1) - max1 = 1 - for i in range(0, len(nums)): - dp.append(1) - #print('i=',i) - #print('dp[i]=',dp[i]) - for j in range(0, i): - print(dp[j]) - if (nums[j] < nums[i]): - dp[i] = max(dp[i], dp[j] + 1) - print(dp[i]) - max1 = max(max1, dp[i]) - print(max1) - return max1 -if __name__=='__main__': - test=[-2,-1] - temp=lengthOfLIS(test) - print(temp) diff --git a/Manjuska/leetcode324.py b/Manjuska/leetcode324.py deleted file mode 100644 index fd05fa55..00000000 --- a/Manjuska/leetcode324.py +++ /dev/null @@ -1,39 +0,0 @@ -class Solution(object): -# partition in place within indices [left, right] inclusive -# change num in place into [...numbersnum[idx]... ] -# return the idx after partition - def partition(self, num, left, right, idx): - num[idx], num[right] = num[right], num[idx] - r1,r2 = right, right - while leftnum[r1]: - num[left], num[r1-1] = num[r1-1], num[left] - num[r2], num[r1-1] = num[r1-1], num[r2] - r1 -= 1 - r2 -= 1 - return r1 - -# again, in place, put kth largest in mid - def findkth(self, num, k): - left, right = 0, len(num)-1 - while leftk: - right = idx-1 - else: - left = idx+1 - - def wiggleSort(self, nums): - mid = len(nums)/2 - self.findkth(nums, mid) # find median and do partition - if len(nums)%2 == 0: - nums[::2], nums[1::2] = nums[:mid][::-1], nums[mid:][::-1] - else: - nums[::2], nums[1::2] = nums[:mid+1][::-1], nums[mid+1:][::-1] \ No newline at end of file diff --git a/Manjuska/leetcode334.py b/Manjuska/leetcode334.py deleted file mode 100644 index c81d71ec..00000000 --- a/Manjuska/leetcode334.py +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def increasingTriplet(self, nums): - """ - :type nums: List[int] - :rtype: bool - """ - big=699999999999 - min_num, a, b = float("inf"), float("inf"), float("inf") - for x in nums: - if x <= min_num: - min_num=x - elif b>=x: - a,b=min_num,x - else: - return True - return False diff --git a/Manjuska/leetcode54.py b/Manjuska/leetcode54.py deleted file mode 100644 index b0c2f00c..00000000 --- a/Manjuska/leetcode54.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def maxSubArray(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - n=len(nums) - ans=nums[0] - dp=[] - dp.append(nums[0]) - for i in range(1,n): - dp.append(max(dp[i-1]+nums[i],nums[i])) - ans=max(dp[i],ans) - return ans diff --git a/MyCodeBattle/Codeforces/Codeforces-11D.cpp b/MyCodeBattle/Codeforces/Codeforces-11D.cpp deleted file mode 100644 index 3fcaa3a8..00000000 --- a/MyCodeBattle/Codeforces/Codeforces-11D.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -#include -#include -//#pragma comment(linker, "/STACK:102400000,102400000") -#include -#include -#include -//using namespace std; -#define LL long long -#define ULL unsigned long long -#define SZ(x) (int)x.size() -#define lowbit(x) ((x) & (-x)) -#define MP(a, b) make_pair(a, b) -#define MS(p, num) memset(p, num, sizeof(p)) -#define PB push_back -#define X first -#define Y second -#define ROP freopen("input.txt", "r", stdin); -#define MID(a, b) (a + ((b - a) >> 1)) -#define LC rt << 1, l, mid -#define RC rt << 1|1, mid + 1, r -#define LRT rt << 1 -#define RRT rt << 1|1 -#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++) -#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++) -const double PI = acos(-1.0); -const int INF = 0x3f3f3f3f; -const double eps = 1e-8; -const int MAXN = 20; -const int MOD = 1e9 + 7; -const int dir[][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}, {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; -const int seed = 131; -int cases = 0; -typedef std::pair pii; - -bool mp[MAXN][MAXN]; -LL dp[1< -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -#include -#include -//#pragma comment(linker, "/STACK:102400000,102400000") -#include -#include -#include -//using namespace std; -#define LL long long -#define ULL unsigned long long -#define SZ(x) (int)x.size() -#define lowbit(x) ((x) & (-x)) -#define MP(a, b) make_pair(a, b) -#define MS(p, num) memset(p, num, sizeof(p)) -#define PB push_back -#define X first -#define Y second -#define ROP freopen("input.txt", "r", stdin); -#define MID(a, b) (a + ((b - a) >> 1)) -#define LC rt << 1, l, mid -#define RC rt << 1|1, mid + 1, r -#define LRT rt << 1 -#define RRT rt << 1|1 -#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++) -#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++) -const double PI = acos(-1.0); -const int INF = 0x3f3f3f3f; -const double eps = 1e-8; -const int MAXN = 10 + 10; -const int MOD = 1e9 + 7; -const int dir[][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}, {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; -const int seed = 131; -int cases = 0; -typedef std::pair pii; - -int dp[MAXN][2][2]; -int buf[100]; -int dfs(int pos, bool isSixSelected, bool isLimited) { - if (pos == -1) return 1; - if (~dp[pos][isSixSelected][isLimited]) return dp[pos][isSixSelected][isLimited]; - int cur = isLimited ? buf[pos] : 9; - - int ret = 0; - for (int i = 0; i <= cur; ++i) { - if ((isSixSelected && i==2) || i == 4) continue; - ret += dfs(pos - 1, i==6, isLimited && i==cur); - } - - return dp[pos][isSixSelected][isLimited] = ret; -} - -int solve(int n) { - MS(dp, -1); - int pos = 0; - while (n) { - buf[pos++] = n % 10; - n /= 10; - } - return dfs(pos - 1, false, true); -} - -int main() { - // ROP; - int n, m; - - while (scanf("%d%d", &n, &m)) { - - if (n + m == 0) break; - printf("%d\n", solve(m) - solve(n - 1)); - } - return 0; -} - diff --git a/MyCodeBattle/LintCode/001. A + B Problem/solution.java b/MyCodeBattle/LintCode/001. A + B Problem/solution.java deleted file mode 100644 index d4ffcd96..00000000 --- a/MyCodeBattle/LintCode/001. A + B Problem/solution.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 我们在二进制位模拟一下即可。 - */ -class Solution { - /* - * param a: The first integer - * param b: The second integer - * return: The sum of a and b - */ - public int aplusb(int a, int b) { - // write your code here, try to do it without arithmetic operators. - boolean carry = false; - int ans = 0; - - for (int i = 0; i < 32; ++i) { - int x = (a & 1), y = (b & 1); - if (x == 1 && y == 1) { - if (carry) { - ans |= (1 << i); - } - else - carry = true; - - } - else if (x == 1) { - if (!carry) - ans |= (1 << i); - } - else if (y == 1) { - if (!carry) - ans |= (1 << i); - } - else { - if (carry) { - ans |= (1 << i); - carry = false; - } - } - a >>= 1; - b >>= 1; - } - - return ans; - } -}; diff --git a/MyCodeBattle/LintCode/002. Trailing Zeros/solution.java b/MyCodeBattle/LintCode/002. Trailing Zeros/solution.java deleted file mode 100644 index b8cb23a5..00000000 --- a/MyCodeBattle/LintCode/002. Trailing Zeros/solution.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 找5. - */ -class Solution { - /* - * param n: As desciption - * return: An integer, denote the number of trailing zeros in n! - */ - public long trailingZeros(long n) { - // write your code here - long ans = 0; - - while (n != 0) { - ans += n / 5; - n /= 5; - } - return ans; - } -}; - diff --git a/MyCodeBattle/LintCode/003. Digit Counts/solution.java b/MyCodeBattle/LintCode/003. Digit Counts/solution.java deleted file mode 100644 index b65bd9c0..00000000 --- a/MyCodeBattle/LintCode/003. Digit Counts/solution.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 也是很经典的题了,考虑每位的贡献即可。 - */ -class Solution { - /* - * param k : As description. - * param n : As description. - * return: An integer denote the count of digit k in 1..n - */ - public int digitCounts(int k, int n) { - // write your code here - if (n < 0) - return 0; - if (n == 0 && k == 0) - return 1; - int pre = n / 10; - int mid = n % 10; - int last = 0, weigh = 1; - - - int ans = 0; - while (n != 0) { - if (pre == 0 && k == 0) - break; - if (mid < k) - ans += pre * weigh; - else if (mid == k) { - ans += pre * weigh + last + 1; - } - else - ans += (pre + 1) * weigh; - last = n%10*weigh + last; - n /= 10; - mid = n % 10; - pre = n / 10; - weigh *= 10; - } - - return ans; - } -} diff --git a/MyCodeBattle/LintCode/004. Ugly Number II/solution.java b/MyCodeBattle/LintCode/004. Ugly Number II/solution.java deleted file mode 100644 index 7d085b2d..00000000 --- a/MyCodeBattle/LintCode/004. Ugly Number II/solution.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 递推丑数,找出最小的一个增加一个因子。 - */ -class Solution { - /** - * @param n an integer - * @return the nth prime number as description. - */ - public int nthUglyNumber(int n) { - // Write your code here - int pos2 = 1, pos3 = 1, pos5 = 1; - int num2 = 2, num3 = 3, num5 = 5; - List arr = new ArrayList<>(); - arr.add(1); - while (arr.size() < n) { - int currentNumber = Math.min(num2, Math.min(num3, num5)); - arr.add(currentNumber); - if (num2 == currentNumber) - num2 = 2 * arr.get(pos2++); - if (num3 == currentNumber) - num3 = 3 * arr.get(pos3++); - if (num5 == currentNumber) - num5 = 5 * arr.get(pos5++); - } - return arr.get(arr.size() - 1); - } -}; - diff --git a/MyCodeBattle/LintCode/005. Kth Largest Element/solution.java b/MyCodeBattle/LintCode/005. Kth Largest Element/solution.java deleted file mode 100644 index 5a17e5e5..00000000 --- a/MyCodeBattle/LintCode/005. Kth Largest Element/solution.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 堆和快排思想都可以,不知道用堆会不会超时。 - */ -import java.lang.Math; - -class Solution { - /* - * @param k : description of k - * @param nums : array of nums - * @return: description of return - */ - - int partition(int[] nums, int l, int r, int k) { - - if (l == r) - return nums[l]; - int idx = l + (int) (Math.random() * (r - l)); - int pivot = nums[idx]; - int temp = nums[r]; - nums[r] = nums[idx]; - nums[idx] = temp; - - int pos = l; - for (int i = l; i < r; ++i) { - if (nums[i] <= pivot) { - temp = nums[i]; - nums[i] = nums[pos]; - nums[pos++] = temp; - } - } - - temp = nums[pos]; - nums[pos++] = nums[r]; - nums[r] = temp; - if (pos - l >= k) - return partition(nums, l, pos - 1, k); - else - return partition(nums, pos, r, k - (pos - l)); - - } - - public int kthLargestElement(int k, int[] nums) { - // write your code here - int n = nums.length; - k = n - k + 1; - return partition(nums, 0, nums.length - 1, k); - } -}; - diff --git a/MyCodeBattle/LintCode/006. Merge Sorted Array II/solution.java b/MyCodeBattle/LintCode/006. Merge Sorted Array II/solution.java deleted file mode 100644 index f2dd1b66..00000000 --- a/MyCodeBattle/LintCode/006. Merge Sorted Array II/solution.java +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { - /** - * @param A and B: sorted integer array A and B. - * @return: A new sorted integer array - */ - public int[] mergeSortedArray(int[] A, int[] B) { - // Write your code here - int len1 = A.length, len2 = B.length; - int pos1 = 0, pos2 = 0, pos = 0; - - int[] buffer = new int[A.length + B.length]; - while (pos1 < len1 && pos2 < len2) - buffer[pos++] = A[pos1] < B[pos2] ? A[pos1++] : B[pos2++]; - while (pos1 < len1) - buffer[pos++] = A[pos1++]; - while (pos2 < len2) - buffer[pos++] = B[pos2++]; - - return buffer; - } -} - diff --git a/MyCodeBattle/LintCode/007. Binary Tree Serialization/solution.java b/MyCodeBattle/LintCode/007. Binary Tree Serialization/solution.java deleted file mode 100644 index ea7d85d6..00000000 --- a/MyCodeBattle/LintCode/007. Binary Tree Serialization/solution.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 模拟前序遍历。 - */ - -/** - * Definition of TreeNode: - * public class TreeNode { - * public int val; - * public TreeNode left, right; - * public TreeNode(int val) { - * this.val = val; - * this.left = this.right = null; - * } - * } - */ -class Solution { - /** - * This method will be invoked first, you should design your own algorithm - * to serialize a binary tree which denote by a root node to a string which - * can be easily deserialized by your own "deserialize" method later. - */ - private StringBuilder sb = new StringBuilder(); - private int pos = 0; - - private void dfs(TreeNode rt) { - if (rt == null) { - sb.append("#,"); - return; - } - sb.append(rt.val + ","); - dfs(rt.left); - dfs(rt.right); - } - - public String serialize(TreeNode root) { - if (root == null) { - return "#"; - } - dfs(root); - return sb.toString(); - } - - /** - * This method will be invoked second, the argument data is what exactly - * you serialized at method "serialize", that means the data is not given by - * system, it's given by your own serialize method. So the format of data is - * designed by yourself, and deserialize it here as you serialize it in - * "serialize" method. - */ - public TreeNode deserialize(String data) { - // write your code here - if (data.charAt(pos) == '#') { - pos += 2; - return null; - } - int limitPos = data.indexOf(",", pos); - TreeNode root = new TreeNode(new Integer(data.substring(pos, limitPos))); - pos = limitPos + 1; - root.left = deserialize(data); - root.right = deserialize(data); - return root; - } - -} - diff --git a/MyCodeBattle/LintCode/008. Rotate String/solution.java b/MyCodeBattle/LintCode/008. Rotate String/solution.java deleted file mode 100644 index c9389a2e..00000000 --- a/MyCodeBattle/LintCode/008. Rotate String/solution.java +++ /dev/null @@ -1,33 +0,0 @@ -public class Solution { - /** - * @param str: an array of char - * @param offset: an integer - * @return: nothing - */ - - char[] str; - public void rotateString(char[] str, int offset) { - // write your code here - if (offset == 0 || str.length == 0) - return; - offset %= str.length; - int len = str.length; - if (offset < 0) - offset = len + offset; - - this.str = str; - reverse(len - offset, len - 1); - reverse(0, len - offset - 1); - reverse(0, len - 1); - } - - private void reverse(int l, int r) { - int left = l, right = r; - while (left < right) { - char temp = str[left]; - str[left] = str[right]; - str[right] = temp; - ++left; --right; - } - } -} diff --git a/MyCodeBattle/LintCode/009. Fizz Buzz/solution.java b/MyCodeBattle/LintCode/009. Fizz Buzz/solution.java deleted file mode 100644 index d62ad73d..00000000 --- a/MyCodeBattle/LintCode/009. Fizz Buzz/solution.java +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { - /** - * param n: As description. - * return: A list of strings. - */ - public ArrayList fizzBuzz(int n) { - ArrayList results = new ArrayList(); - for (int i = 1; i <= n; i++) { - if (i % 15 == 0) { - results.add("fizz buzz"); - } else if (i % 5 == 0) { - results.add("buzz"); - } else if (i % 3 == 0) { - results.add("fizz"); - } else { - results.add(String.valueOf(i)); - } - } - return results; - } -} - diff --git a/MyCodeBattle/LintCode/011. Search Range in Binary Search Tree/solution.java b/MyCodeBattle/LintCode/011. Search Range in Binary Search Tree/solution.java deleted file mode 100644 index c1ca67db..00000000 --- a/MyCodeBattle/LintCode/011. Search Range in Binary Search Tree/solution.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Definition of TreeNode: - * public class TreeNode { - * public int val; - * public TreeNode left, right; - * public TreeNode(int val) { - * this.val = val; - * this.left = this.right = null; - * } - * } - */ -public class Solution { - /** - * @param root: The root of the binary search tree. - * @param k1 and k2: range k1 to k2. - * @return: Return all keys that k1<=key<=k2 in ascending order. - */ - ArrayList ans = new ArrayList<>(); - - public ArrayList searchRange(TreeNode root, int k1, int k2) { - // write your code here - if (root == null) - return ans; - if (root.val >= k1 && root.val <= k2) { - searchRange(root.left, k1, k2); - ans.add(root.val); - searchRange(root.right, k1, k2); - } - else if (root.val < k1) { - searchRange(root.right, k1, k2); - } - else { - searchRange(root.left, k1, k2); - } - return ans; - } -} diff --git a/MyCodeBattle/LintCode/012. Min Stack/solution.java b/MyCodeBattle/LintCode/012. Min Stack/solution.java deleted file mode 100644 index 25ed4ac5..00000000 --- a/MyCodeBattle/LintCode/012. Min Stack/solution.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 在要更新最小值的时候填上当前的最小值。 - */ -public class MinStack { - Stack stack = new Stack(); - int minValue = Integer.MAX_VALUE; - - public MinStack() { - // do initialize if necessary - } - - public void push(int number) { - if (number <= minValue) { - stack.push(minValue); - minValue = number; - } - stack.push(number); - } - - public int pop() { - int ret = 0; - - if (stack.peek() == minValue) { - ret = stack.pop(); - minValue = stack.pop(); - } - else { - ret = stack.pop(); - } - return ret; - } - - public int min() { - return minValue; - } -} - diff --git a/MyCodeBattle/LintCode/013. strStr/solution.java b/MyCodeBattle/LintCode/013. strStr/solution.java deleted file mode 100644 index 678360ab..00000000 --- a/MyCodeBattle/LintCode/013. strStr/solution.java +++ /dev/null @@ -1,26 +0,0 @@ -class Solution { - /** - * Returns a index to the first occurrence of target in source, - * or -1 if target is not part of source. - * @param source string to be scanned. - * @param target string containing the sequence of characters to match. - */ - public int strStr(String source, String target) { - if (source == null || target == null || source.length() < target.length()) - return -1; - - for (int i = 0; i < source.length() - target.length() + 1; ++i) { - boolean flag = true; - - for (int j = 0; j < target.length(); ++j) { - if (source.charAt(i + j) != target.charAt(j)) { - flag = false; - break; - } - } - if (flag) - return i; - } - return -1; - } -} diff --git a/MyCodeBattle/LintCode/014. First Position of Target/solution.java b/MyCodeBattle/LintCode/014. First Position of Target/solution.java deleted file mode 100644 index a1becdef..00000000 --- a/MyCodeBattle/LintCode/014. First Position of Target/solution.java +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { - /** - * @param nums: The integer array. - * @param target: Target to find. - * @return: The first position of target. Position starts from 0. - */ - public int binarySearch(int[] nums, int target) { - if (nums.length == 0) - return -1; - int l = 0, r = nums.length; - while (l < r) { - int mid = (l + r) / 2; - if (nums[mid] >= target) - r = mid; - else - l = mid + 1; - } - return nums[l] == target ? l : -1; - } -} diff --git a/MyCodeBattle/LintCode/015. Permutations/solution.java b/MyCodeBattle/LintCode/015. Permutations/solution.java deleted file mode 100644 index ab440c81..00000000 --- a/MyCodeBattle/LintCode/015. Permutations/solution.java +++ /dev/null @@ -1,50 +0,0 @@ -class Solution { - /** - * @param nums: A list of integers. - * @return: A list of permutations. - */ - - private void reverse(int l, int r, ArrayList ans) { - while (l < r) { - int temp = ans.get(l); - ans.set(l, ans.get(r)); - ans.set(r, temp); - ++l; --r; - } - } - - private boolean nextPermutation(ArrayList nums) { - int i = nums.size() - 1; - while (i != 0 && nums.get(i - 1) >= nums.get(i)) { - --i; - } - if (i == 0) - return false; - - int swapPos = i - 1; - while (i < nums.size() && nums.get(i) > nums.get(swapPos)) - ++i; - - int temp = nums.get(i - 1); - nums.set(i - 1, nums.get(swapPos)); - nums.set(swapPos, temp); - - reverse(swapPos + 1, nums.size() - 1, nums); - return true; - } - - public ArrayList> permute(ArrayList nums) { - ArrayList> ans = new ArrayList<>(); - - if (nums == null) - return ans; - Collections.sort(nums); - - do { - ans.add((ArrayList) nums.clone()); - } while (nextPermutation(nums)); - - return ans; - } -} - diff --git a/MyCodeBattle/LintCode/016. Permutations II/solution.java b/MyCodeBattle/LintCode/016. Permutations II/solution.java deleted file mode 100644 index a0887d38..00000000 --- a/MyCodeBattle/LintCode/016. Permutations II/solution.java +++ /dev/null @@ -1,51 +0,0 @@ -class Solution { - /** - * @param nums: A list of integers. - * @return: A list of permutations. - */ - - private void reverse(int l, int r, ArrayList ans) { - while (l < r) { - int temp = ans.get(l); - ans.set(l, ans.get(r)); - ans.set(r, temp); - ++l; --r; - } - } - - private boolean nextPermutation(ArrayList nums) { - int i = nums.size() - 1; - while (i != 0 && nums.get(i - 1) >= nums.get(i)) { - --i; - } - if (i == 0) - return false; - - int swapPos = i - 1; - while (i < nums.size() && nums.get(i) > nums.get(swapPos)) - ++i; - - int temp = nums.get(i - 1); - nums.set(i - 1, nums.get(swapPos)); - nums.set(swapPos, temp); - - reverse(swapPos + 1, nums.size() - 1, nums); - return true; - } - - public ArrayList> permuteUnique(ArrayList nums) { - ArrayList> ans = new ArrayList<>(); - - if (nums == null) - return ans; - Collections.sort(nums); - - do { - ans.add((ArrayList) nums.clone()); - } while (nextPermutation(nums)); - - return ans; - } -} - - diff --git a/MyCodeBattle/LintCode/017. Subsets/solution.java b/MyCodeBattle/LintCode/017. Subsets/solution.java deleted file mode 100644 index 22001e55..00000000 --- a/MyCodeBattle/LintCode/017. Subsets/solution.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 当前一个数字相同并且没选的时候,轮不到自己选。 - */ -class Solution { - /** - * @param S: A set of numbers. - * @return: A list of lists. All valid subsets. - */ - ArrayList> ans = new ArrayList<>(); - boolean[] visited; - - private void dfs(int pos, ArrayList lis, int[] nums) { - if (pos == nums.length) { - ans.add((ArrayList) lis.clone()); - return; - } - - if (pos == 0 || nums[pos] != nums[pos - 1] || visited[pos - 1]) { - visited[pos] = true; - lis.add(nums[pos]); - dfs(pos + 1, lis, nums); - visited[pos] = false; - lis.remove(lis.size() - 1); - } - dfs(pos + 1, lis, nums); - } - - public ArrayList> subsets(int[] nums) { - if (nums.length == 0) - return ans; - Arrays.sort(nums); - visited = new boolean[nums.length]; - - dfs(0, new ArrayList(), nums); - return ans; - } -} diff --git a/MyCodeBattle/LintCode/018. Subsets II/solution.java b/MyCodeBattle/LintCode/018. Subsets II/solution.java deleted file mode 100644 index b908dd67..00000000 --- a/MyCodeBattle/LintCode/018. Subsets II/solution.java +++ /dev/null @@ -1,35 +0,0 @@ -class Solution { - /** - * @param S: A set of numbers. - * @return: A list of lists. All valid subsets. - */ - ArrayList> ans = new ArrayList<>(); - boolean[] visited; - - private void dfs(int pos, ArrayList lis, ArrayList nums) { - if (pos == nums.size()) { - ans.add((ArrayList) lis.clone()); - return; - } - - if (pos == 0 || nums.get(pos) != nums.get(pos - 1) || visited[pos - 1]) { - visited[pos] = true; - lis.add(nums.get(pos)); - dfs(pos + 1, lis, nums); - visited[pos] = false; - lis.remove(lis.size() - 1); - } - dfs(pos + 1, lis, nums); - } - - public ArrayList> subsetsWithDup(ArrayList nums) { - if (nums.size() == 0) - return ans; - Collections.sort(nums); - visited = new boolean[nums.size()]; - - dfs(0, new ArrayList(), nums); - return ans; - } -} - diff --git a/MyCodeBattle/LintCode/028. Search a 2D Matrix/solution.java b/MyCodeBattle/LintCode/028. Search a 2D Matrix/solution.java deleted file mode 100644 index d71ce259..00000000 --- a/MyCodeBattle/LintCode/028. Search a 2D Matrix/solution.java +++ /dev/null @@ -1,47 +0,0 @@ -public class Solution { - /** - * @param matrix, a list of lists of integers - * @param target, an integer - * @return a boolean, indicate whether matrix contains target - */ - - private int[][] m; - - private int searchRow(int target) { - int l = 0, r = m.length; - while (l < r) { - int mid = (l + r) >> 1; - if (m[mid][0] > target) - r = mid; - else - l = mid + 1; - } - if (l == 0 && m[l][0] > target) - return -1; - return --l; - } - - private boolean searchColumn(int row, int target) { - int l = 0, r = m[0].length; - while (l < r) { - int mid = (l + r) >> 1; - if (m[row][mid] >= target) - r = mid; - else - l = mid + 1; - } - return l != m[0].length && m[row][l] == target; - } - - public boolean searchMatrix(int[][] matrix, int target) { - if (matrix.length == 0 || matrix[0].length == 0) - return false; - this.m = matrix; - - int row = searchRow(target); - if (row == -1) - return false; - return searchColumn(row, target); - } -} - diff --git a/MyCodeBattle/LintCode/029. Interleaving String/solution.java b/MyCodeBattle/LintCode/029. Interleaving String/solution.java deleted file mode 100644 index b0247a78..00000000 --- a/MyCodeBattle/LintCode/029. Interleaving String/solution.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * dp[i][j],第一个匹配到i第二个匹配到j匹配的第三个长度。 - */ -import java.lang.Math; - -public class Solution { - /** - * Determine whether s3 is formed by interleaving of s1 and s2. - * @param s1, s2, s3: As description. - * @return: true or false. - */ - public boolean isInterleave(String s1, String s2, String s3) { - if (s1 == null && s2 == null && s3 == null) - return true; - if (s3.length() == 0 && s1.length() == 0 && s2.length() == 0) - return true; - if (s1 == null || s2 == null || s3 == null || s3.length() != s1.length() + s2.length()) - return false; - - int[][] dp = new int[s1.length() + 2][s2.length() + 2]; - - for (int i = 0; i <= s1.length(); ++i) { - for (int j = 0; j <= s2.length(); ++j) { - int pos = dp[i][j]; - if (i != s1.length() && s1.charAt(i) == s3.charAt(pos)) - dp[i + 1][j] = Math.max(dp[i + 1][j], pos + 1); - if (j != s2.length() && s2.charAt(j) == s3.charAt(pos)) - dp[i][j + 1] = Math.max(dp[i][j + 1], pos + 1); - } - } - return dp[s1.length()][s2.length()] == s3.length(); - } -} diff --git a/MyCodeBattle/LintCode/030. Insert Interval/solution.java b/MyCodeBattle/LintCode/030. Insert Interval/solution.java deleted file mode 100644 index 79171306..00000000 --- a/MyCodeBattle/LintCode/030. Insert Interval/solution.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Definition of Interval: - * public classs Interval { - * int start, end; - * Interval(int start, int end) { - * this.start = start; - * this.end = end; - * } - */ - -class Solution { - /** - * Insert newInterval into intervals. - * @param intervals: Sorted interval list. - * @param newInterval: A new interval. - * @return: A new sorted interval list. - */ - public ArrayList insert(ArrayList intervals, Interval newInterval) { - ArrayList result = new ArrayList(); - if (newInterval == null) - return intervals; - int l = newInterval.start, r = newInterval.end; - - for (Interval i: intervals) { - //先排除不在区间内的 - if (i.end < l) - result.add(i); - else if (i.start > r) { - if (l <= r) { - result.add(new Interval(l, r)); - l = r + 1; - } - result.add(i); - } - else { - l = Math.min(l, i.start); - r = Math.max(r, i.end); - } - } - if (l <= r) - result.add(new Interval(l, r)); - return result; - } -} diff --git a/MyCodeBattle/LintCode/031. Partition Array/solution.java b/MyCodeBattle/LintCode/031. Partition Array/solution.java deleted file mode 100644 index f0d784f6..00000000 --- a/MyCodeBattle/LintCode/031. Partition Array/solution.java +++ /dev/null @@ -1,32 +0,0 @@ -public class Solution { - /** - *@param nums: The integer array you should partition - *@param k: As description - *return: The index after partition - */ - - private void swap(int[] nums, int l, int r) { - int temp = nums[r]; - nums[r] = nums[l]; - nums[l] = temp; - } - - public int partitionArray(int[] nums, int k) { - if (nums.length == 0) - return 0; - int l = 0, r = nums.length - 1; - for (int i = 0; i < nums.length && i <= r; ++i) { - int u = nums[i]; - if (nums[i] < k) { - swap(nums, i, l++); - } - else if (nums[i] > k) { - swap(nums, i, r--); - --i; - } - } - return l; - } - -} - diff --git a/MyCodeBattle/LintCode/032. Minimum Window Substring/solution.java b/MyCodeBattle/LintCode/032. Minimum Window Substring/solution.java deleted file mode 100644 index 98cbaaa6..00000000 --- a/MyCodeBattle/LintCode/032. Minimum Window Substring/solution.java +++ /dev/null @@ -1,47 +0,0 @@ -public class Solution { - /** - * @param source: A string - * @param target: A string - * @return: A string denote the minimum window - * Return "" if there is no such a string - */ - public String minWindow(String source, String target) { - int[] cnt = new int[300]; - int[] need = new int[300]; - - if (source == null || target == null || target.equals("")) - return ""; - - int all = 0; - for (int i = 0; i < target.length(); ++i) { - ++need[(int) target.charAt(i)]; - if (need[(int) target.charAt(i)] == 1) - ++all; - } - - String ret = ""; - int start = 0, minLen = Integer.MAX_VALUE; - int rem = 0; - for (int i = 0; i < source.length(); ++i) { - char u = source.charAt(i); - ++cnt[(int) u]; - if (cnt[(int) u] == need[(int) u]) { - ++rem; - } - if (rem == all) { - while (rem == all) { - int k = (int) source.charAt(start); - if (--cnt[k] < need[k]) - --rem; - ++start; - } - if (i - start < minLen) { - minLen = i - start; - ret = source.substring(start - 1, i + 1); - } - } - - } - return ret; - } -} diff --git a/MyCodeBattle/LintCode/033. N-Queens/solution.java b/MyCodeBattle/LintCode/033. N-Queens/solution.java deleted file mode 100644 index ba1f2387..00000000 --- a/MyCodeBattle/LintCode/033. N-Queens/solution.java +++ /dev/null @@ -1,38 +0,0 @@ -class Solution { - /** - * Get all distinct N-Queen solutions - * @param n: The number of queens - * @return: All distinct solutions - * For example, A string '...Q' shows a queen on forth position - */ - ArrayList> ans = new ArrayList<>(); - ArrayList curAns = new ArrayList<>(); - private int n; - - private boolean check(int pos, int v) { - return ((v >> pos) & 1) != 1; - } - - private void dfs(int layer, int columnVis, int lVis, int rVis) { - if (layer == n) { - ans.add(new ArrayList(curAns)); - return; - } - for (int i = 0; i < n; ++i) if (check(i, columnVis) && check(i - layer + n, lVis) && check(i + layer, rVis)) { - StringBuilder sb = new StringBuilder(); - for (int j = 0; j < n; ++j) sb.append('.'); - sb.setCharAt(i, 'Q'); - curAns.add(sb.toString()); - dfs(layer + 1, columnVis|(1<> solveNQueens(int n) { - this.n = n; - if (n == 0) - return ans; - dfs(0, 0, 0, 0); - return ans; - } -}; diff --git a/MyCodeBattle/LintCode/034. N-Queens II/solution.java b/MyCodeBattle/LintCode/034. N-Queens II/solution.java deleted file mode 100644 index f54659fa..00000000 --- a/MyCodeBattle/LintCode/034. N-Queens II/solution.java +++ /dev/null @@ -1,35 +0,0 @@ -class Solution { - /** - * Get all distinct N-Queen solutions - * @param n: The number of queens - * @return: All distinct solutions - * For example, A string '...Q' shows a queen on forth position - */ - int ans; - private int n; - - private boolean check(int pos, int v) { - return ((v >> pos) & 1) != 1; - } - - private void dfs(int layer, int columnVis, int lVis, int rVis) { - if (layer == n) { - ++ans; - return; - } - for (int i = 0; i < n; ++i) if (check(i, columnVis) && check(i - layer + n, lVis) && check(i + layer, rVis)) { - StringBuilder sb = new StringBuilder(); - for (int j = 0; j < n; ++j) sb.append('.'); - dfs(layer + 1, columnVis|(1< -#define MAXN 100007 -using namespace std; - -int a[MAXN][12]; -int n,x,y,maxt,ans; - -int MAX3(int a ,int b, int c){ - if(a>b&&a>c) return a; - if(b>c) return b; - return c; -} - -int main() -{ - while(scanf("%d",&n) && n){ - memset(a,0,sizeof(a)); - maxt = ans = 0; - while(n--){ - scanf("%d%d",&x,&y); - if(abs(x-5)>y) continue; - a[y][x]++; - if(y>maxt) maxt = y; - } - for(int i=1;i<=maxt;i++){ - a[i][0] += MAX3(0,a[i-1][0],a[i-1][1]); - for(int j=1;j<11;j++) { - a[i][j] += MAX3(a[i-1][j-1],a[i-1][j],a[i-1][j+1]); - if(a[i][j] > ans) ans = a[i][j]; - } - } - printf("%d\n",ans); - } - return 0; -} diff --git a/NIghtLemon/HDU1506.cpp b/NIghtLemon/HDU1506.cpp deleted file mode 100644 index abf1b1d1..00000000 --- a/NIghtLemon/HDU1506.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -using namespace std; -#define MAXN 100007 -typedef long long ll; -int n,t; -ll a[MAXN],b[MAXN],c[MAXN]; -ll ans; - -int main() -{ - while(scanf("%d",&n) && n!=0){ - b[0] = 0; a[n+1] = 0; - ans = 0; - for(int i=1; i<=n; i++){ - scanf("%d",&t); a[i] = t; - } - b[1] = 1; c[n] = n; - for(int i=2; i<=n ;i++){ - t = i; - while(t>1 && a[i] <= a[t-1]) - t = b[t-1]; - b[i] = t; - } - ans = (n - b[n] +1) * a[n]; - for(int i=n-1; i; i--){ - t = i; - while(t ans ) - ans = (c[i] - b[i] + 1)*a[i]; - } - printf("%I64d\n",ans); - } - return 0; -} diff --git a/NIghtLemon/HDU1556.cpp b/NIghtLemon/HDU1556.cpp deleted file mode 100644 index 61f911d8..00000000 --- a/NIghtLemon/HDU1556.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -using namespace std; - -struct noname { - int x,y; - noname() {} - noname(int a,int b){ - this->x = a; - this->y = b; - } -} a[200007]; - -int n,tot,x,y,now; -char pe[3] = " \n"; - - -void qs(int l,int r){ - int i=l,j=r, x = a[(l+r)/2].x; - noname T; - while(1){ - while(a[i].x < x) i++; - while(a[j].x > x) j--; - if(i<=j){ - T = a[i]; - a[i] = a[j]; - a[j] = T; - i++;j--; - } else break; - } - if(i -using namespace std; - -int n,m,ans,T,tot,sumv; -int A[107]; -int a[100007]; -int v[100007]; - -int main() -{ - while(scanf("%d%d",&n,&m) && n){ - memset(a,0,sizeof(a)); - memset(v,0,sizeof(v)); - tot = 0; ans = 0; sumv = 0; - for(int i=1 ; i<=n; i++) scanf("%d",&A[i]); - for(int i=1 ; i<=n; i++){ - int j=1; - scanf("%d",&T); - while(T){ - a[++tot] = j*A[i]; - T -=j; - j = j + j; - if(T=a[i];j--) - v[j] = (v[j] || v[j-a[i]]); - } - T = min(sumv,m); - for(int i=1;i<=T;i++) ans+=v[i]; - printf("%d\n",ans); - } - return 0; -} diff --git a/NIghtLemon/HDU3549.cpp b/NIghtLemon/HDU3549.cpp deleted file mode 100644 index 54fea4a7..00000000 --- a/NIghtLemon/HDU3549.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -using namespace std; -const int MAXNODE = 105*2; -const int MAXEDGE = 100005; - -typedef int Type; -const Type INF = 0x3f3f3f3f; - -struct Edge{ - int u,v; - Type cap,flow; - Edge() {} - Edge(int u,int v,Type cap,Type flow){ - this->u = u; - this->v = v; - this->cap = cap; - this->flow = flow; - } -}; -struct Dinic{ - int n,m,s,t; - Edge edges[MAXEDGE]; - int first[MAXNODE]; - int next[MAXEDGE]; - bool vis[MAXNODE]; - Type d[MAXNODE]; - int cur[MAXNODE]; - vectorcut; - void init(int n){ - this->n = n; - memset(first,-1,sizeof(first)); - m=0; - } - void add_Edge(int u,int v,Type cap){ - edges[m] = Edge(u,v,cap,0); - next[m] = first[u]; - first[u] = m++; - edges[m] = Edge(v,u,0,0); - next[m] = first[v]; - first[v] = m++; - } - bool bfs(){ - memset(vis,false,sizeof(vis)); - queueQ; - Q.push(s); - d[s]=0; - vis[s] = true; - while(!Q.empty()){ - int u = Q.front(); - Q.pop(); - for(int i = first[u];i != -1;i = next[i]){ - Edge&e = edges[i]; - if(!vis[e.v]&&e.cap>e.flow){ - vis[e.v] = true; - d[e.v] = d[u]+1; - Q.push(e.v); - } - } - } - return vis[t]; - } - Type dfs(int u,Type a){ - if(u==t||a==0)return a; - Type flow = 0,f; - for(int &i=cur[u]; i != -1;i = next[i]){ - Edge&e = edges[i]; - if (d[u] + 1 == d[e.v] && (f = dfs(e.v, min(a, e.cap - e.flow)))>0){ - e.flow += f; - edges[i^1].flow -= f; - flow += f; - a -= f; - if(a==0)break; - } - } - return flow; - } - Type Maxflow(int s,int t){ - this->s=s; this->t=t; - Type flow=0; - while(bfs()){ - for(int i = 0; i < n; i++) - cur[i] = first[i]; flow += dfs(s,INF); - } - return flow; - } - void MinCut(){ - cut.clear(); - for(int i = 0; i < m; i += 2){ - if(vis[edges[i].u] && !vis[edges[i].v]) - cut.push_back(i); - } - } -}gao; - -int main() -{ - int T , NT = 0 , n , m , x, y ,z; - scanf("%d",&T); - while(T--){ - scanf("%d%d",&n,&m); - gao.init(n); - for(int i=1;i<=m;i++){ - scanf("%d%d%d",&x,&y,&z); - gao.add_Edge(x,y,z); - } - printf("Case %d: %d\n",++NT,gao.Maxflow(1,n)); - } - return 0; -} diff --git a/NIghtLemon/HDU5656.cpp b/NIghtLemon/HDU5656.cpp deleted file mode 100644 index 61c539fe..00000000 --- a/NIghtLemon/HDU5656.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#define MAXN 1007 -using namespace std; -typedef long long ll; - -int n; -ll G[MAXN][MAXN]; -ll a[MAXN]; -ll dp[MAXN][MAXN]; -ll MAXn,tmp,ans; - -const ll MOD = 100000007; - -ll gcd(ll x, ll y){ - if(y) return gcd(y,x%y); - return x; -} - -void init() -{ - for(int i=0;i<=1000;i++) - for(int j=0;j<=1000;j++) - G[i][j] = gcd(i,j); -} - -int main() -{ - init(); - int T; - cin>>T; - while(T--){ - cin>>n; - ans = 0; - memset(dp,0,sizeof(dp)); dp[0][0] = 1LL; - MAXn = 0LL; - for(int i=1; i<=n ;i++){ - cin>>a[i]; - if(a[i] > MAXn) MAXn = a[i]; - } - for(int i=1; i<=n ;i++){ - for(int j=0; j<=MAXn ;j++){ - dp[i][j] = (dp[i][j] + dp[i-1][j] ) % MOD; - tmp = G[j][a[i]]; - dp[i][tmp] = (dp[i][tmp] + dp[i-1][j]) %MOD; - } - } - for(int i=1; i<=MAXn ; i++) - ans = (ans + dp[n][i] * i) %MOD; - cout< -/**周五十节课,两份实验报告 - *很惭愧,来不及了,刷了道水题来凑数 - *5月7日补两道以做弥补 - * by NightLemon - */ -using namespace std; -typedef long long ll; -int main() -{ - int T; - ll n; - cin>>T; - while(T--){ - cin>>n; - if(n==3 ||(n>4) && (n%4!=2)) cout<<"True"< -//#Motzkin Number 默慈金数 -//#Catalan Number 卡塔兰数 -//#线性求逆元 -using namespace std; - -#define MAXN 1000007 -typedef long long ll; -const ll MOD = 1000000007; - -ll remod[MAXN]; -ll a[MAXN]; - -void init() -{ - remod[1] = 1LL; - for(int i=2;i>T; - while(T--){ - cin>>n; - if(n>Nmax) { - for(ll i=Nmax +1; i<=n; i++) - a[i] = ((a[i-1] * (2*(i-1)+3) +3*(i-1)*a[i-2]) % MOD * remod[i-1+3])% MOD; - Nmax = n; - } - cout< -using namespace std; - -#define LL long long - -const int maxn = 20; -int tw[maxn],num[maxn]; -int dp[maxn][200000]; - -int dfs(int pos,bool bnd,int lef){ - if(pos < 0) return lef >= 0; - if(lef < 0) return 0; - int &ndp = dp[pos][lef]; - if(!bnd && ndp != -1){ - return ndp; - } - int ret = 0; - int bound = bnd ? num[pos] : 9; - for(int i=0;i<=bound;i++){ - if(i * tw[pos] > lef) - break; - ret += dfs(pos-1,bnd && i==bound,lef - i*tw[pos]); - } - if(!bnd) - ndp = ret; - return ret; -} - -int cw(int x){ - int ret = 0,len = 0; - while(x){ - ret += tw[len]*(x%10); - x /= 10; - len++; - } - return ret; -} - -int cal(int b,int a){ - int len = 0; - a = cw(a); - while(b){ - num[len++] = b % 10; - b /= 10; - } - return dfs(len-1,true,a); -} - -int main(){ - tw[0] = 1; - for(int i=1;i -using namespace std; -#define LL long long -const int INF = 0x3f3f3f3f; - -int lis[24][4]; - -void initp(){ - for(int i=0;i<4;i++){ - lis[0][i] = i + 1; - } - for(int j=1;j<24;j++){ - for(int i=0;i<4;i++){ - lis[j][i] = lis[j-1][i]; - } - next_permutation(lis[j],lis[j]+4); - } -} - -const int maxn = 5123; -int arr[maxn][8]; - -bool legal(int *cho,int *fig){ - for(int i=0;i<4;i++){ - for(int j=0;j<4;j++){ - if(fig[i] > fig[j] && cho[i*2+1] < cho[j*2+1]) - return false; - } - } - return true; -} - -int calcost(int *bcho,int *bfig,int *acho,int *afig){ - int ret = 0; - for(int i=0;i<4;i++){ - for(int j=0;j<4;j++){ - if(bfig[i] == afig[j]){ - ret += abs(bcho[i*2]-acho[j*2]); - ret += abs(bcho[i*2+1]-acho[j*2+1]); - } - } - } - return ret; -} - -int dp[maxn][24]; - -int main(){ - initp(); - int T,icase = 1; - for(int i=0;i<8;i++){ - arr[0][i] = i%2?i/2+1:0; - } - - scanf("%d",&T); - int n; - while(T-- && ~scanf("%d",&n)){ - memset(dp,0x3f,sizeof(dp)); - dp[0][0] = 0; - for(int i=1;i<=n;i++){ - for(int j=0;j<8;j++) scanf("%d",&arr[i][j]); - for(int j=0;j<24;j++){ - if(!legal(arr[i],lis[j])) continue; - for(int k=0;k<24;k++){ - dp[i][j]=min(dp[i][j],dp[i-1][k]+calcost(arr[i-1],lis[k],arr[i],lis[j])); - } - } - } - int ans = INF; - for(int i=0;i<24;i++){ - ans = min(dp[n][i],ans); - } - printf("Case #%d:\n%d\n",icase++,ans); - } - return 0; -} - -``` - diff --git a/QAsQ/Blog/Poj 1741 Tree.md b/QAsQ/Blog/Poj 1741 Tree.md deleted file mode 100644 index 34bd9675..00000000 --- a/QAsQ/Blog/Poj 1741 Tree.md +++ /dev/null @@ -1,145 +0,0 @@ -# Poj 1741 Tree - -树分治入门题 - -如果你要学习树分治,请按照以下步骤 - -首先你要知道什么是树的重心,并且能在dfs过程中找到树的重心 - -然后你要理解树分治的分治过程,能知道每一次分治的时候对于每一个子树都要找一次重心,并且能写出每次找重心的代码 - -最后是具体题面具体分析,知道如何在分治过程中统计答案 - - - -对于这个这个题来说,要统计的是树上路径和小于k的点对 - - - -我们考虑过重心的路径,记录$bel_x$为$x$所在的子树编号,$lener_x$为$x$到重心的距离 - -对于过重心的路径要统计的就是$bel_x \ne bel_y,lener_x+lener_y\le k$的点对的个数 - -然后对于这个$= 所有的lener_x+lener_y\le k 的点对个数 \\-(bel_x=bel_y,)lener_x+lener_y\le k 的点对个数$ - -然后就好求了,具体见代码 - -```cpp -#include -#include -#include -#include -using namespace std; -const int inf = 0x3f3f3f3f; -const int maxn = 11234; - -vector >edge[maxn]; - -void init(int n){ - for(int i=0;i<=n;i++){ - edge[i].clear(); - } -} - -void Link(int st,int ed,int v){ - edge[st].push_back(make_pair(ed,v)); - edge[ed].push_back(make_pair(st,v)); -} - -bool vis[maxn]; -int siz[maxn],msiz[maxn]; - -int lener[maxn],len; - -int k; - -int calroot(int st,int fa,int all){ - int ret = -1; - siz[st] = 1,msiz[st] = 0; - for(vector >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first; - if(x != fa && !vis[x]){ - int trot = calroot(x,st,all); - if(ret==-1 || msiz[ret]>msiz[trot]) - ret = trot; - siz[st] += siz[x]; - msiz[st] = max(msiz[st],siz[x]); - } - } - msiz[st] = max(msiz[st],all - siz[st]); - if(ret==-1 || msiz[ret]>msiz[st]) - ret = st; - return ret; -} - -int getpair(){ - int ret = 0; - sort(lener,lener+len); - int pos = len-1; - for(int i=0;i=0 && lener[pos]+lener[i]>k){ - pos--; - } - ret += max(pos-i,0); - } - return ret; -} - -void getlener(int st,int fa,int v){ - lener[len++] = v; - for(vector >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first,tv = it->second; - if(x != fa && vis[x]==false){ - getlener(x,st,v+tv); - } - } -} - -void outlener(){ - for(int i=0;i >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first,v = it->second; - if(vis[x]) continue; - len = 0; - getlener(x,st,v); - ans -= getpair(); - ans += dfs(calroot(x,st,siz[x])); - } - return ans; -} - -int cal(int n){ - memset(vis,0,sizeof(vis)); - return dfs(calroot(1,0,n)); -} - -int main(){ - int n; - while(~scanf("%d %d",&n,&k) && (n||k)){ - int x,y,v; - init(n); - for(int i=1;i -using namespace std; - -const int maxn = 1123456; -#define LL long long -LL pri[maxn]; -LL unp[maxn]; - -void sieve(){ - memset(pri,-1,sizeof(pri)); - pri[1] = 1; - unp[1] = 1; - for(LL i=2;i -using namespace std; - -const int maxn = 1123456; -#define LL long long -int pri[maxn]; - -void sieve(){ - memset(pri,-1,sizeof(pri)); - pri[1] = 1; - for(LL i=2;i -using namespace std; - -const int maxn = 21234; -vector >edge[maxn]; - -void init(int n){ - for(int i=0;i<=n;i++){ - edge[i].resize(0); - } -} - -void Link(int st,int ed,int v){ - v %= 3; - edge[st].push_back(make_pair(ed,v)); - edge[ed].push_back(make_pair(st,v)); -} - -int dp[maxn][3]; -int cnt[maxn]; - -void dfs(int st,int fa){ - cnt[st] = 1; - dp[st][0] = 1; - for(vector >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first; - int v = it->second; - if(x!=fa){ - dfs(x,st); - cnt[st] += cnt[x]; - for(int i=0;i<3;i++) cnt[st] += dp[st][i]*dp[x][(6-i-v)%3]; - for(int i=0;i<3;i++) dp[st][(i+v)%3] += dp[x][i]; - } - } -} - -int main(){ - int n; - while(~scanf("%d",&n)){ - init(n); - int x,y,v; - for(int i=1;i -using namespace std; -#define LL long long -const LL INFF = 0x3f3f3f3f3f3f3f3fll; - -const int maxn = 121345; - -LL rex[maxn]; -LL rey[maxn]; - -double caldis(LL x1,LL y1,LL x2,LL y2){ - LL x = x1 - x2; - LL y = y1-y2; - LL su = x * x + y * y; - return sqrt((double)su); -} - -double caldis(int id,LL x,LL y){ - return caldis(rex[id],rey[id],x,y); -} - -void can(LL x,LL y,LL tx,LL ty,int n,int &id,int &bd,double &dif1,double &dif2){ - bd = -1; - dif1 = caldis(0,x,y) - caldis(0,tx,ty); - id = 0; - for(int i=1;i>ax>>ay>>bx>>by>>tx>>ty; - int n; - cin>>n; - for(int i=0;i>rex[i]>>rey[i]; - double all = 0; - for(int i=0;i -using namespace std; -#define LL long long -const LL INFF = 0x3f3f3f3f3f3f3f3fll; - -const int maxn = 512345; - -LL arr[maxn]; - -LL calans(int n,LL k){ - LL sum = 0; - for(int i=1;i<=n;i++){ - sum+=arr[i]; - } - LL down = sum / n; - LL up = down; - if(sum%n) - up++; - sort(arr+1,arr+n+1); - if(k == 0){ - return arr[n] - arr[1]; - } - LL rd = down,ru = up; - if(n == 2){ - LL ned = down - arr[1] + arr[2] - up; - if(ned <= k){ - return ru - rd; - } - else{ - return arr[2]-k-(arr[1]+k); - } - } - LL use = 0; - for(int i=2;i<=n;i++){ - LL nu = (arr[i]-arr[i-1])*(i-1); - if(use + nu < k) - use += nu; - else{ - rd = arr[i-1] + (k - use) / (i-1); - break; - } - } - use = 0; - for(int i = n-1;i>=1;i--){ - LL nu = (arr[i+1]-arr[i]) * (n-i); - if(use + nu < k){ - use += nu; - } - else{ - ru = arr[i+1] - (k-use)/(n-i); - break; - } - } - ru = max(ru,up); - rd = min(rd,down); - return ru - rd; -} - -int main(){ - ios::sync_with_stdio(false); - int n; - LL k; - cin>>n>>k; - LL sum = 0; - for(int i=1;i<=n;i++){ - cin>>arr[i]; - } - cout< -using namespace std; - -#define LL long long - -const int maxn = 20; -int tw[maxn],num[maxn]; -int dp[maxn][200000]; - -int dfs(int pos,bool bnd,int lef){ - if(pos < 0) return lef >= 0; - if(lef < 0) return 0; - int &ndp = dp[pos][lef]; - if(!bnd && ndp != -1){ - return ndp; - } - int ret = 0; - int bound = bnd ? num[pos] : 9; - for(int i=0;i<=bound;i++){ - if(i * tw[pos] > lef) - break; - ret += dfs(pos-1,bnd && i==bound,lef - i*tw[pos]); - } - if(!bnd) - ndp = ret; - return ret; -} - -int cw(int x){ - int ret = 0,len = 0; - while(x){ - ret += tw[len]*(x%10); - x /= 10; - len++; - } - return ret; -} - -int cal(int b,int a){ - int len = 0; - a = cw(a); - while(b){ - num[len++] = b % 10; - b /= 10; - } - return dfs(len-1,true,a); -} - -int main(){ - tw[0] = 1; - for(int i=1;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define LL long long - -using namespace std; - -double bn[5][5],x[5],y[5]; -int kr; -int n,m; - -int vis[5][5][5][5]; - -bool cro(int i,int j,int k,int l){ - if(i == 2 && j == 2) - return false; - if(i != 2 && j != 2){ - return i == k || j == l; - } - if(i != 2){ - return i == k; - } - if(j != 2){ - return j == l; - } -} - - -double caler(int X,int Y){ - x[0] = X-1; - x[1] = 1; - x[2] = n - X; - y[0] = Y-1; - y[1] = 1; - y[2] = m-Y; - for(int i =0;i<3;i++){ - for(int j=0;j<3;j++){ - bn[i][j] = x[i] * y[j]; - } - } - double fm = n * m; - fm *= fm; - double fz = 0; - for(int i=0;i<3;i++){ - for(int j=0;j<3;j++){ - double mid = 0; - for(int k=0;k<3;k++){ - for(int l=0;l<3;l++){ - if(vis[i][j][k][l]){ - mid += bn[k][l]; - } - } - } - fz += bn[i][j] * mid; - } - } - double ans = fz; - ans /= fm; - double r = 1; - for(int i=0;i -using namespace std; -#define LL long long -const int INF = 0x3f3f3f3f; - -int lis[24][4]; - -void initp(){ - for(int i=0;i<4;i++){ - lis[0][i] = i + 1; - } - for(int j=1;j<24;j++){ - for(int i=0;i<4;i++){ - lis[j][i] = lis[j-1][i]; - } - next_permutation(lis[j],lis[j]+4); - } -} - -const int maxn = 5123; -int arr[maxn][8]; - -bool legal(int *cho,int *fig){ - for(int i=0;i<4;i++){ - for(int j=0;j<4;j++){ - if(fig[i] > fig[j] && cho[i*2+1] < cho[j*2+1]) - return false; - } - } - return true; -} - -int calcost(int *bcho,int *bfig,int *acho,int *afig){ - int ret = 0; - for(int i=0;i<4;i++){ - for(int j=0;j<4;j++){ - if(bfig[i] == afig[j]){ - ret += abs(bcho[i*2]-acho[j*2]); - ret += abs(bcho[i*2+1]-acho[j*2+1]); - } - } - } - return ret; -} - -int dp[maxn][24]; - -int main(){ - initp(); - int T,icase = 1; - for(int i=0;i<8;i++){ - arr[0][i] = i%2?i/2+1:0; -// printf(i<7?"%d ":"%d\n",arr[0][i]); - } - - scanf("%d",&T); - int n; - while(T-- && ~scanf("%d",&n)){ - memset(dp,0x3f,sizeof(dp)); - dp[0][0] = 0; - for(int i=1;i<=n;i++){ - for(int j=0;j<8;j++) scanf("%d",&arr[i][j]); - for(int j=0;j<24;j++){ - if(!legal(arr[i],lis[j])) continue; -// for(int l = 0;l<4;l++){ -// printf(l<3?"%d ":"%d\n",lis[j][l]); -// } -// printf("at = %d fing = %d\n",i,j); - for(int k=0;k<24;k++){ - dp[i][j]=min(dp[i][j],dp[i-1][k]+calcost(arr[i-1],lis[k],arr[i],lis[j])); -// printf("sta = %d af = %d bef = %d\n",i,j,k); -// getchar(); - } - } - } - int ans = INF; - for(int i=0;i<24;i++){ - ans = min(dp[n][i],ans); - } - printf("Case #%d:\n%d\n",icase++,ans); - } - return 0; -} diff --git a/QAsQ/SDUT/3257.cpp b/QAsQ/SDUT/3257.cpp deleted file mode 100644 index 119e4d0a..00000000 --- a/QAsQ/SDUT/3257.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -using namespace std; - -const int maxn = 1123456; -#define LL long long -LL pri[maxn]; -LL unp[maxn]; - -void sieve(){ - memset(pri,-1,sizeof(pri)); - pri[1] = 1; - unp[1] = 1; - for(LL i=2;i -using namespace std; - -const int maxn = 1123456; -#define LL long long -int pri[maxn]; - -void sieve(){ - memset(pri,-1,sizeof(pri)); - pri[1] = 1; - for(LL i=2;i -using namespace std; - -const int maxn = 21234; -vector >edge[maxn]; - -void init(int n){ - for(int i=0;i<=n;i++){ - edge[i].resize(0); - } -} - -void Link(int st,int ed,int v){ - v %= 3; - edge[st].push_back(make_pair(ed,v)); - edge[ed].push_back(make_pair(st,v)); -} - -int dp[maxn][3]; -int cnt[maxn]; - -void dfs(int st,int fa){ - cnt[st] = 1; - dp[st][0] = 1; - for(vector >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first; - int v = it->second; - if(x!=fa){ - dfs(x,st); - cnt[st] += cnt[x]; - for(int i=0;i<3;i++) cnt[st] += dp[st][i]*dp[x][(6-i-v)%3]; - for(int i=0;i<3;i++) dp[st][(i+v)%3] += dp[x][i]; - } - } -} - -int main(){ - int n; - while(~scanf("%d",&n)){ - init(n); - int x,y,v; - for(int i=1;i -using namespace std; - -#define LL long long -const int maxn = 70; - -LL n[maxn],m[maxn],k[maxn]; -LL p; - -LL cnt[maxn][2][2][2],dp[maxn][2][2][2]; -LL tw[maxn]; - -void biter(LL x,LL *s){ - for(int i = 0;i= k[pos]){ - ncnt += dfsn(pos-1,un && i==nb,um && j == mb,uk && x==k[pos]); - ncnt %= p; - } - } - } - return ncnt; -} - -LL dfs(int pos,bool un,bool um,bool uk){ - if(pos < 0) return 0; - LL & ndp = dp[pos][un][um][uk]; - if(ndp != -1) - return ndp; - int nb = un ? n[pos] : 1; - int mb = um ? m[pos] : 1; - ndp = 0; - for(int i=0;i<=nb;i++){ - for(int j=0;j<=mb;j++){ - LL x = i ^ j; - if(!uk || x >= k[pos]){ - LL mid = x; - mid *= dfsn(pos-1,un && i== nb,um && j == mb,uk && x==k[pos]); - (mid *= tw[pos]) %= p; - ndp += mid; - (ndp += dfs(pos-1,un && i== nb,um && j == mb,uk && x==k[pos])) %= p; - } - } - } - return ndp; -} - -LL cal(LL N,LL M,LL K){ - tw[0] = 1; - for(int i=1;i>T; - while(T-- && cin>>N>>M>>K>>p){ - cout< -#include -#include -#include -using namespace std; -const int inf = 0x3f3f3f3f; -const int maxn = 11234; - -vector >edge[maxn]; - -void init(int n){ - for(int i=0;i<=n;i++){ - edge[i].clear(); - } -} - -void Link(int st,int ed,int v){ - edge[st].push_back(make_pair(ed,v)); - edge[ed].push_back(make_pair(st,v)); -} - -bool vis[maxn]; -int siz[maxn],msiz[maxn]; - -int lener[maxn],len; - -int k; - -int calroot(int st,int fa,int all){ - int ret = -1; - siz[st] = 1,msiz[st] = 0; - for(vector >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first; - if(x != fa && !vis[x]){ - int trot = calroot(x,st,all); - if(ret==-1 || msiz[ret]>msiz[trot]) - ret = trot; - siz[st] += siz[x]; - msiz[st] = max(msiz[st],siz[x]); - } - } - msiz[st] = max(msiz[st],all - siz[st]); - if(ret==-1 || msiz[ret]>msiz[st]) - ret = st; - return ret; -} - -int getpair(){ - int ret = 0; - sort(lener,lener+len); - int pos = len-1; - for(int i=0;i=0 && lener[pos]+lener[i]>k){ - pos--; - } - ret += max(pos-i,0); - } - return ret; -} - -void getlener(int st,int fa,int v){ - lener[len++] = v; - for(vector >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first,tv = it->second; - if(x != fa && vis[x]==false){ - getlener(x,st,v+tv); - } - } -} - -void outlener(){ - for(int i=0;i >::iterator it = edge[st].begin();it!=edge[st].end();it++){ - int x = it->first,v = it->second; - if(vis[x]) continue; - len = 0; - getlener(x,st,v); - ans -= getpair(); - ans += dfs(calroot(x,st,siz[x])); - } - return ans; -} - -int cal(int n){ - memset(vis,0,sizeof(vis)); - return dfs(calroot(1,0,n)); -} - -int main(){ - int n; - while(~scanf("%d %d",&n,&k) && (n||k)){ - int x,y,v; - init(n); - for(int i=1;i edge[maxn]; - - -int fa[maxn],son[maxn],siz[maxn],deep[maxn],top[maxn],tid[maxn]; -int _cnt; - -void dffs(int st,int Fa,int Deep){ - siz[st] = 1,deep[st] = Deep; - fa[st] = Fa,son[st] = -1; - for(auto &x:edge[st]){ - if(x != Fa){ - dffs(x,st,Deep+1); - siz[st] += siz[x]; - if(son[st] == -1 || siz[son[st]] < siz[x]) - son[st] = x; - } - } -} - -void dfss(int st,int Top){ - top[st] = Top,tid[st] = _cnt++; - if(son[st] != -1) - dfss(son[st],Top); - for(auto &x:edge[st]){ - if(son[st] != x && fa[st] != x){ - dfss(x,x); - } - } -} - -void splite(){ - _cnt = 1; - dffs(ROOT,-1,0); - dfss(ROOT,ROOT); -} - -int QUE_or_UPD(int x,int y){ - int ret = 0; - int tx = top[x],ty = top[y]; - while(tx != ty){ - if(deep[tx] < deep[ty]) - swap(tx,ty),swap(x,y); - ret += qu(root,tid[tx],tid[x]); - x = fa[tx],tx = top[x]; - } - if(deep[x] < deep[y]) - swap(x,y); - ret += qu(root,tid[y],tid[x]); - return ret; -} - diff --git a/QAsQ/template/DateStruct/mo's_algorithm.cpp b/QAsQ/template/DateStruct/mo's_algorithm.cpp deleted file mode 100644 index abb0d84b..00000000 --- a/QAsQ/template/DateStruct/mo's_algorithm.cpp +++ /dev/null @@ -1,74 +0,0 @@ -struct Ask -{ - int l,r; - int id; - LL ans; - void init(int i) - { - scanf("%d %d",&l,&r); - id = i; - } -}; - -Ask ask[maxn]; -int unit; - -bool cmpmo(Ask a,Ask b) -{ - if(a.l / unit != b.l / unit) - return a.l < b.l; - return a.r < b.r; -} - -bool cmpid(Ask a,Ask b) -{ - return a.id < b.id; -} - -LL renew(LL ans,int pos,bool adder) -{ - - if(adder) - { - //add - } - else - { - //del - } - return ans; -} - -int main() -{ - scanf("%d %d",&n,&m); - unit = (int)sqrt(n*1.0); - for(int i=0; imsiz[trot]) - ret = trot; - siz[st] += siz[x]; - msiz[st] = max(msiz[st],siz[x]); - } - } - msiz[st] = max(msiz[st],all - siz[st]); - if(ret==-1 || msiz[ret]>msiz[st]) - ret = st; - return ret; -} -int dfs(int st){ - vis[st] = true; - int ans = 0; - len = 0; - - \\update rooter - - for(auto x :edge[st]){ - if(vis[x]) continue; - - \\update soner - - ans += dfs(calroot(x,st,siz[x])); - } - return ans; -} -int cal(int n){ - memset(vis,0,sizeof(vis)); - return dfs(calroot(1,0,n)); -} - - diff --git a/QAsQ/template/Math/BSGS.cpp b/QAsQ/template/Math/BSGS.cpp deleted file mode 100644 index 8da2c861..00000000 --- a/QAsQ/template/Math/BSGS.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -map x; - -int log_mod(int a,int b,int n){ - int m, v, e=1; - m=(int)sqrt(n+0.5); - v=inv(pow_mod(a , m, n), n); - x.clear(); - x[1]=0; - for(int i = 1;i < m; i++){ - e=mul_mod(e, a, n); - if(!x.count[e]) x[e] = i; - } - for(int i = 0;i < m; i++){ - if(x.count(b)) return i*m+x[b]; - b=mul_mod(b,v,n); - } - return -1; -} - diff --git a/QAsQ/template/Math/CRT.cpp b/QAsQ/template/Math/CRT.cpp deleted file mode 100644 index 99d46dac..00000000 --- a/QAsQ/template/Math/CRT.cpp +++ /dev/null @@ -1,114 +0,0 @@ -//中国剩余定理(互质版 (gcd(a[i], b[i])==1)) -#include -#define LL long long -LL a[15], b[15]; - -LL Extend_Euclid(LL a, LL b, LL&x, LL& y) -{ - if(b == 0) - { - x = 1, y = 0; - return a; - } - LL d = Extend_Euclid(b, a%b, x, y); - LL t = x; - x = y; - y = t - a/b*y; - return d; -} -//求解模线性方程组x=ai(mod ni) -LL China_Reminder(int len, LL* a, LL* n) -{ - int i; - LL N = 1; - LL result = 0; - for(i = 0; i < len; i++) - N = N*n[i]; - for(i = 0; i < len; i++) - { - LL m = N/n[i]; - LL x, y; - Extend_Euclid(m, n[i], x, y); - x = (x%n[i]+n[i])%n[i]; - result = (result + m*a[i]*x%N)%N; - } - return result; -} - -int main() -{ - int n; - while(~scanf("%d", &n)) - { - for(int i = 0; i < n; i++) - scanf("%I64d %I64d", &a[i], &b[i]); - printf("%I64d\n",China_Reminder(n, b, a)); - } - return 0; -} -//中国剩余定理(不互质版(gcd(a[i], b[i]有可能不为1)) -//不互质版可以过互质版的题,但对于互质的题,不互质版时间效率稍逊。 -#include -#define LL long long -long long Mod; - -long long gcd(long long a, long long b) -{ - if(b == 0) return a; - return gcd(b, a%b); -} - -//a在模n乘法下的逆元,没有则返回-1 -long long inv(long long a, long long n) -{ - long long x, y; - long long t = exgcd(a, n, x, y); - if(t != 1) return -1; - return (x%n+n)%n; -} -//将两个方程合并为一个 -bool merge(long long a1, long long n1, long long a2, long long n2, long long& a3, long long& n3) -{ - long long d = gcd(n1,n2); - long long c = a2-a1; - if(c%d) return false; - c = (c%n2+n2)%n2; - c /= d; - n1 /= d; - n2 /= d; - c *= inv(n1, n2); - c %= n2; - c *= n1*d; - c += a1; - n3 = n1*n2*d; - a3 = (c%n3+n3)%n3; - return true; -} -///求模线性方程组x=ai(mod ni),ni可以不互质 -long long China_Reminder2(int len, long long* a, long long* n) -{ - long long a1 = a[0], n1 = n[0]; - long long a2, n2; - for(int i = 1; i < len; i++) - { - long long aa, nn; - a2 = a[i], n2 = n[i]; - if(!merge(a1, n1, a2, n2, aa, nn)) return -1; - a1 = aa; - n1 = nn; - } - Mod = n1; - return (a1%n1+n1)%n1; -} -long long a[1000], b[1000]; -int main() -{ - int k; - while(~scanf("%d", &k)) - { - for(int i = 0; i < k; i++) - scanf("%I64d %I64d",&a[i],&b[i]); - printf("%I64d\n", China_Reminder2(k, b, a)); - } - return 0; -} diff --git a/QAsQ/template/Math/Simpson.cpp b/QAsQ/template/Math/Simpson.cpp deleted file mode 100644 index 16e17ec5..00000000 --- a/QAsQ/template/Math/Simpson.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -double simpson(double a,double b){ - double c = a + (b-a)/2; - return (F(a)+4*F(c)+F(b))*(b-a)/6; -} - - -double asr(double a,double b,double eps,double A){ - double c = a + (b-a)/2; - double L = simpson(a,c), R = simpson(c,b); - if(fabs(L+R-A) <= 15*eps) return (L+R-A)/15.0; - return asr(a,c,eps/2,L) + asr(c,b,eps/2,R); -} - -// 计算区间 a 到 b 的 F 的积分值 -double asr(double a,double b,double eps){ - return asr(a,b,eps,simpson(a,b)); -} diff --git a/QAsQ/template/Math/exgcd.cpp b/QAsQ/template/Math/exgcd.cpp deleted file mode 100644 index 2863f8e2..00000000 --- a/QAsQ/template/Math/exgcd.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -using namespace std; - -#define LL long long - -LL extend_gcd(LL a,LL b,LL &x,LL &y) -{ - if(a==0&&b==0) return -1;//无最大公约数 - if(b==0) - { - x=1,y=0; - return a; - } - LL d=extend_gcd(b,a%b,y,x); - y-=a/b*x; - return d; -} - diff --git a/QAsQ/template/Math/getFactor.cpp b/QAsQ/template/Math/getFactor.cpp deleted file mode 100644 index 8b20a383..00000000 --- a/QAsQ/template/Math/getFactor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - O(sqrt(n)) - factor[][0] is prime factor - factor[][1] is factor generated by this prime - factor[][2] is factor counter - - (需要先筛素数) -*/ - -int factor[100][3],facCnt; -int getFactors(int x){ - facCnt = 0; - int tem = x; - for(int i = 1; prime[i] <= tem / prime[i]; i++){ - factor[facCnt][1] = 1,factor[facCnt][2] = 0; - if(tem % prime[i] == 0) - factor[facCnt][0] = prime[i]; - while(tem % prime[i] == 0){ - factor[facCnt][2]++; - factor[facCnt][1] *= prime[i]; - tem /=prime[i]; - } - if(factor[facCnt][1] > 1) facCnt++; - } - if(tem != 1){ - factor[facCnt][0] = tem; - factor[facCnt][1] = tem, factor[facCnt++][2] = 1; - } - return facCnt; -} diff --git a/QAsQ/template/Math/getPrime.cpp b/QAsQ/template/Math/getPrime.cpp deleted file mode 100644 index 9aeb22d9..00000000 --- a/QAsQ/template/Math/getPrime.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -using namespace std; - -const int plen=1123456; - -int prime[plen+1]; -int mobius[plen+1]; -int getPrime(){ - memset(prime,0,sizeof(prime)); - memset(mobius,0,sizeof(mobius)); - mobius[1]=0; - for(int i = 2; i<=plen; i++){ - if(!prime[i]) prime[++prime[0]] = i , mobius[i] = -1; - for(int j = 1; j <= prime[0] && prime[j] <=plen / i; j++){ - prime[prime[j]*i] = 1; - if (i % prime[j] == 0) break; - else mobius[i*prime[j]] = -mobius[i]; - } - } - return prime[0]; -} - diff --git a/QAsQ/template/Math/inv.cpp b/QAsQ/template/Math/inv.cpp deleted file mode 100644 index 409b8a53..00000000 --- a/QAsQ/template/Math/inv.cpp +++ /dev/null @@ -1,15 +0,0 @@ -//ax = 1(mod n) -long long mod_reverse(long long a,long long n) -{ - long long x,y; - long long d=extend_gcd(a,n,x,y); - if(d==1) return (x%n+n)%n; - else return -1; -} - -//这个只能求 a < m 的情况,而且必须保证 a 和 m 互质 -long long inv(long long a,long long m) -{ - if(a == 1)return 1; - return inv(m%a,m)*(m-m/a)%m; -} diff --git a/QAsQ/template/Math/mobius.cpp b/QAsQ/template/Math/mobius.cpp deleted file mode 100644 index 21a7ec25..00000000 --- a/QAsQ/template/Math/mobius.cpp +++ /dev/null @@ -1,19 +0,0 @@ -const int maxn = 10086; - -int mobius[maxn]; - -int main(){ - memset(mobius,0,sizeof(mobius)); - for(int i=1;itz(); - for(int i=0;i0) - { - if(n & 1) - res=res*x; - x=x*x; - n >>= 1; - } - return res; -} - diff --git a/QAsQ/template/Math/powerMod.cpp b/QAsQ/template/Math/powerMod.cpp deleted file mode 100644 index 558b731d..00000000 --- a/QAsQ/template/Math/powerMod.cpp +++ /dev/null @@ -1,12 +0,0 @@ -//x^k % m - -LL powerMod(LL x, LL k, LL m) -{ - LL res = 1; - while(x %= m, k) - { - if(k&1) res *= x, res %= m; - x *= x, k >>=1; - } - return res; -} diff --git a/QAsQ/template/Math/some_Math.cpp b/QAsQ/template/Math/some_Math.cpp deleted file mode 100644 index 1a50005f..00000000 --- a/QAsQ/template/Math/some_Math.cpp +++ /dev/null @@ -1,44 +0,0 @@ -1~n 中和 n 互质的数的个数 - n * φ(n) / 2 - -线性求逆元 - inv[i] = (MOD - MOD/i) * inv[MOD%i] %MOD - -设 a > 1, m,n>0 ,那么有 gcd(a^m-1, a^n-1) = a^gcd(m,n) - 1 -设 a>b, gcd(a,b)=1 ,那么 gcd(a^m-b^m, a^n-b^n) = a^gcd(m,n) - b^gcd(m,n) - -设 F(n) 为 Fib 数,那么有 gcd( F(m), F(n) ) = F( gcd(m,n) ) (n+1) - -lcm( C(n,0) , C(n,1) , ... C(n,n) ) = lcm(1, 2, ... , n+1) - -如果 fib(k) 能被 x 整除, 则 fib(k*i) 都可以被 x 整除 - -3.f(0)+f(1)+f(2)+…+f(n)=f(n+2)-1 -4.f(1)+f(3)+f(5)+…+f(2n-1)=f(2n) -5.f(2)+f(4)+f(6)+…+f(2n) =f(2n+1)-1 -6.[f(0)]^2+[f(1)]^2+…+[f(n)]^2=f(n)?f(n+1) -7.f(0)-f(1)+f(2)-…+(-1)^n*f(n)=(-1)^n*[f(n+1)-f(n)]+1 -8.f(n+m)=f(n+1)?f(m)+f(n)*f(m-1) -9.[f(n)]^2=(-1)^(n-1)+f(n-1)?f(n+1) -10.f(2n-1)=[f(n)]^2-[f(n-2)]^2 -11.3f(n)=f(n+2)+f(n-2) -12.f(2n-2m-2)[f(2n)+f(2n+2)]=f(2m+2)+f(4n-2m) -[n 〉m>=-1 && n>=1 ] - -第一类 stirling 数 S(p,k)的一个组合学解释是: -将p个物体划分成k个非空的不可辨别的 -(可以理解为盒子没有编号)集合的方法数。 - -S(p,k) = (p-1)*S(p-1,k) + S(p-1, k-1), 1<=k<=p-1 - -第二类 stirling 数 n 个有区别的球放到 m 个相同的盒子中, -要求无一空盒,其不同的方案数用 S(n,m) 表示 -S(n, m) = k*S(n-1,m) + S(n-1,m-1) -每个贝尔数都是"第二类 Stirling 数"的和 -B(n) = sigma( S(n,k) ) 1<=k<=n B(n+1) = sigma( C(n,k) B(k) ) 0 <= k <= n - -若 p 是任意质数, B(p+n) = B(n)+B(n+1) (mod p) - -Fib 数模 p^m 的最小循环节长度等于 G(p)p^(m-1) ,其中 G(p) 表示 Fib 数模素数 p 的最小循环节长度。 - -如果 5 是模 p 的二次剩余, 那么长度为 p-1 的因子,否则是 2(p+1) 的因子 diff --git "a/QAsQ/template/Math/\345\222\214\350\216\253\346\257\224\344\271\214\346\226\257\345\207\275\346\225\260\345\215\267\347\247\257.cpp" "b/QAsQ/template/Math/\345\222\214\350\216\253\346\257\224\344\271\214\346\226\257\345\207\275\346\225\260\345\215\267\347\247\257.cpp" deleted file mode 100644 index e3c68e2a..00000000 --- "a/QAsQ/template/Math/\345\222\214\350\216\253\346\257\224\344\271\214\346\226\257\345\207\275\346\225\260\345\215\267\347\247\257.cpp" +++ /dev/null @@ -1,19 +0,0 @@ -#include -using namespace std; - -int g[150]; -int n = 100; - -int main(){ - memset(g,0,sizeof(g)); - g[1] = 1; - for(int i=1;i<=n;i++){ - for(int j=i+i;j<=n;j+=i){ - g[j] -= g[i]; - } - } - for(int i=1;i<=10;i++){ - printf(i<10?"%d ":"%d\n",g[i]); - } - return 0; -} diff --git a/Snickeen/201605054_hiho1295.cpp b/Snickeen/201605054_hiho1295.cpp deleted file mode 100644 index 11dde755..00000000 --- a/Snickeen/201605054_hiho1295.cpp +++ /dev/null @@ -1,19 +0,0 @@ -//练习一下欧拉线性筛质数 -#include -#define N 1000000+3 -int n,i,j; -int pri[N],pn[N/10]; -int main(){ - for(i=2;i -using namespace std; -typedef long long LL; -#define rep(i,a,b) for(i=a;i=b;i--) -struct TT{ - int a,b; -};TT tt[200011],ss[200011]; -int ff,n,m,i,j,k,l,t,s,r,mmax,mmin,num,ans; -LL MOD=1e9+7; -int cmp3(TT a,TT b){return a.a>1; - if(ss[mid].a==e) return mid; - if(ess[mid].a) left=mid+1; - } - return 0; -} - -int main(){ - scanf("%d",&n); - repu(i,1,n)scanf("%d",&ss[i].a); - scanf("%d",&m); - rep(i,0,m)scanf("%d",&tt[i].a); - rep(i,0,m)scanf("%d",&tt[i].b); - - sort(ss+1,ss+n+1,cmp3); - ss[0].a=ss[0].b=0; - j=1;ss[j].b=1; - repu(i,2,n){ - if(ss[i].a==ss[i-1].a)ss[j].b++; - else { - ss[++j].a=ss[i].a; - ss[j].b=1; - } - } - r=bs(tt[0].a,1,j); - s=bs(tt[0].b,1,j); - mmax=ss[r].b; - num=mmax+ss[s].b; - ans=0; - - rep(i,1,m){ - r=bs(tt[i].a,1,j); - s=bs(tt[i].b,1,j); - if(ss[r].b>mmax||(ss[r].b==mmax&&ss[s].b+mmax>num)){ - mmax=ss[r].b; - num=mmax+ss[s].b; - ans=i; - } - } - printf("%d\n",ans+1); - return 0; -} - - -/* -//v2.0 STL 436 ms 21600 KB - -#include -using namespace std; -#define rep(i,a,b) for(i=a;i<=b;i++) -map num; -int n,m,a[200005],r,s,i,ans,maxa=-1,sum=-1; -int main() -{ - scanf("%d",&n); - rep(i,1,n)scanf("%d",&m),num[m]++; - scanf("%d",&n); - rep(i,1,n)scanf("%d",&a[i]); - rep(i,1,n){ - scanf("%d",&m); - r=num[a[i]];s=num[m]; - if(r>maxa||(r==maxa&&s+r>sum))maxa=r,sum=r+s,ans=i; - } - printf("%d\n",ans); - return 0; -} - -*/ diff --git "a/Snickeen/201605076_Snickeen001_\345\220\210\346\263\225\346\213\254\345\217\267.cpp" "b/Snickeen/201605076_Snickeen001_\345\220\210\346\263\225\346\213\254\345\217\267.cpp" deleted file mode 100644 index 1e507ef1..00000000 --- "a/Snickeen/201605076_Snickeen001_\345\220\210\346\263\225\346\213\254\345\217\267.cpp" +++ /dev/null @@ -1,45 +0,0 @@ -/* -//记笔记记笔记 - Problem Description - 小冬认为的合法括号序列跟别人不一样。长度为n的括号序列, - 只要任意前缀中左括号的数量减去右括号的数量小于等于a且大于等于0就是合法的。 - 小冬想知道长度为n的合法序列有多少。 - Input - 输入n,a.(1<=a<=n<=1000) - Output - 输出合法序列MOD 10^9+7 - Sample Input - 1 1 - 2 2 - Sample Output - 1 - 2 -*/ - -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -int ff[1011][1011],n,m,t,s,r,i,j,k,l; -LL ans,MOD=1e9+7; -int main() -{ - while(scanf("%I64d %I64d",&n,&m)!=EOF){ - memset(ff,0,sizeof(ff)); - ff[1][1]=1;m=min(m,n); - for(i=2;i<=n;i++){ - ff[0][i]=ff[1][i-1]%MOD; - for(j=1;j -using namespace std; -int n,m,a,b,c,d,i; -int main(){ - scanf("%d%d %d%d%d%d",&n,&m,&a,&b,&c,&d); - if(n==4||m -int a[111][111],k,n; - -void catalan() -{ - int i,j,t,yu,len; - a[2][0]=a[1][0]=a[0][0]=1; - a[2][1]=2; - a[1][1]=a[0][1]=len=1; - for(i=3;i<=105;i++){ - yu=0; - for(j=1;j<=len;j++){ - t=a[i-1][j]*(4*i-2)+yu; - yu=t/10; - a[i][j]=t%10; - } - while(yu){ - a[i][++len]=yu%10; - yu/=10; - } - for(j=len;j;j--){ - t=a[i][j]+yu*10; - a[i][j]=t/(i+1); - yu=t%(i+1); - } - while(!a[i][len])len--; - a[i][0]=len; - } -} - -int main() -{ - catalan(); - while(~scanf("%d",&n)){ - for(k=a[n][0];k;k--)printf("%d",a[n][k]); - puts(""); - } - return 0; -} diff --git "a/Snickeen/201605102_Snickeen002_\346\212\275\347\255\276\351\227\256\351\242\230.cpp" "b/Snickeen/201605102_Snickeen002_\346\212\275\347\255\276\351\227\256\351\242\230.cpp" deleted file mode 100644 index 2e9989e4..00000000 --- "a/Snickeen/201605102_Snickeen002_\346\212\275\347\255\276\351\227\256\351\242\230.cpp" +++ /dev/null @@ -1,46 +0,0 @@ -/* - 挑战程序设计上的抽签问题,学习二分中 -*/ - -#include -#include -#include -using namespace std; -typedef long long LL; -#define rep(i,a,b) for(i=a;i=1){ - int i=(l+r)/2; - if(kk[i]==x)return true; - else if(kk[i] -#include -using namespace std; -int a[1000007],n,m,t,i,*k; -int main() -{ - while(~scanf("%d",&n)){ - for(i=0;i -#include -using namespace std; -int a[1000007],n,m,t,s,r,i,j,*k; -int main() -{ - while(~scanf("%d",&n)){ - for(i=0;i -using namespace std; -#define rep(i,a,b) for(i=a;i=b;i--) -#define CC(a) memset(a,0,sizeof(a)) - -#define N 500000+7 -int pre[N],last[N],cnt[N],n,m,t,s,r,i,j,k,l,pos; -char aa[N],op[N]; -stack q; - -int main() -{ - scanf("%d%d%d%s%s",&n,&m,&k,aa+1,op+1); - repu(i,1,n){ - if(aa[i]=='(')q.push(i); - else { - t=q.top();q.pop(); - cnt[t]=i;cnt[i]=t; - } - } - repu(i,0,n)last[i]=i+1,pre[i]=i-1; - pre[0]=last[n]=0;pos=k; - repu(i,1,m){ - if(op[i]=='L'){pos=pre[pos];continue;} - if(op[i]=='R'){pos=last[pos];continue;} - - if(aa[pos]=='('){ - t=cnt[pos];r=pre[pos];s=last[t]; - last[r]=s;pre[s]=r; - if(s==0)pos=r; - else pos=s; - } - else if(aa[pos]==')'){ - t=cnt[pos];r=pre[t];s=last[pos]; - last[r]=s;pre[s]=r; - if(s==0)pos=r; - else pos=s; - } - } - for(i=0;i<=n&&last[i];){ - i=last[i]; - printf("%c",aa[i]); - }puts(""); - return 0; -} diff --git a/Snickeen/201605135_CF671A.cpp b/Snickeen/201605135_CF671A.cpp deleted file mode 100644 index 523d285a..00000000 --- a/Snickeen/201605135_CF671A.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - 题意:两个人捡瓶子到固定点。关键地方是找到两个人一开始捡哪两个或一个瓶子。 - - 一开始ans初始化为1e9+7,结果WA在45,然后改成1e22+7后AC。后来将cin/cout改为scanf/printf时用1e10+7也AC。 - - 以前打CF基本上只用bits/stdc++.h,这次没用,原来setprecision(12)需要包含头文件iomanip,记笔记记笔记。 - - 先用cin和cout: 1669 ms 2200 KB - 后用scanf和printf: 156 ms 2200 KB - -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -typedef unsigned long long ULL; -#define rep(i,a,b) for(i=a;i=b;i--) -#define db double -#define ld long double -#define FIN freopen("in.txt","r",stdin) -#define FOUT freopen("out.txt","w",stdout) -#define CC(a) memset(a,0,sizeof(a)) -struct TT{ - int a,b,dir; -};TT tt[1]; -LL ff[11],dd[11],n,m,i,j,k,l;db t,s,r,mmax,mmin,num,ans,sa,sb; -LL MOD=1e9+7; -char aa[111]; - -int main(){ -// FIN;FOUT; - db ax,ay,bx,by,cx,cy,x,y,z; -// cin>>ax>>ay>>bx>>by>>cx>>cy>>n; - scanf("%lf %lf %lf %lf %lf %lf %d",&ax,&ay,&bx,&by,&cx,&cy,&n); - ans=1e10+7; - while(n--){ -// cin>>x>>y; - scanf("%lf %lf",&x,&y); - r=hypot(ax-x,ay-y); - s=hypot(bx-x,by-y); - t=hypot(cx-x,cy-y); - r-=t;s-=t; - num+=t*2; - ans=min(ans,sa+s); - ans=min(ans,sb+r); - sa=min(sa,r); - sb=min(sb,s); - } -// cout< -#include -#include -using namespace std; -#define MAXN 111111 - -struct Edge{ - int v,w,next; -}edge[MAXN<<1]; -int NE,head[MAXN]; -void addEdge(int u,int v,int w){ - edge[NE].v=v; edge[NE].w=w; edge[NE].next=head[u]; - head[u]=NE++; -} - -int dep[MAXN],par[17][MAXN],upp[17][MAXN]; -void dfs(int u,int fa){ - for(int i=head[u]; i!=-1; i=edge[i].next){ - int v=edge[i].v; - if(v==fa) continue; - dep[v]=dep[u]+1; - par[0][v]=u; - upp[0][v]=edge[i].w; - dfs(v,u); - } -} - -void init(int n){ - for(int i=1; i<17; ++i){ - for(int j=1; j<=n; ++j){ - if(par[i-1][j]==0){ - par[i][j]=0; - continue; - } - par[i][j]=par[i-1][par[i-1][j]]; - if(upp[i-1][j]==1 && upp[i-1][par[i-1][j]]==1){ - upp[i][j]=1; - }else if(upp[i-1][j]==-1 && upp[i-1][par[i-1][j]]==-1){ - upp[i][j]=-1; - }else{ - upp[i][j]=0; - } - } - } -} - -bool lca(int u,int v){ - if(dep[u]>dep[v]){ - for(int i=0; i<17; ++i){ - if((dep[u]-dep[v])>>i&1){ - if(upp[i][u]!=1) return 0; - u=par[i][u]; - } - } - if(u==v) return 1; - for(int i=16; i>=0; --i){ - if(par[i][u]!=par[i][v]){ - if(upp[i][u]!=1 || upp[i][v]!=-1) return 0; - u=par[i][u]; v=par[i][v]; - } - } - if(upp[0][u]!=1 || upp[0][v]!=-1) return 0; - }else{ - for(int i=0; i<17; ++i){ - if((dep[v]-dep[u])>>i&1){ - if(upp[i][v]!=-1) return 0; - v=par[i][v]; - } - } - if(u==v) return 1; - for(int i=16; i>=0; --i){ - if(par[i][u]!=par[i][v]){ - if(upp[i][u]!=1 || upp[i][v]!=-1) return 0; - u=par[i][u]; v=par[i][v]; - } - } - if(upp[0][u]!=1 || upp[0][v]!=-1) return 0; - } - return 1; -} - -int main(){ - int n,q,a,b; - while(~scanf("%d",&n)){ - NE=0; - memset(head,-1,sizeof(head)); - for(int i=1; i -#include -#include -#include -using namespace std; -#define INF (1<<30) -#define MAXN 33333 -#define MAXM 66666*2 - -struct Edge{ - int v,w,next; -}edge[MAXM]; -int NE,head[MAXN]; -void addEdge(int u,int v,int w){ - edge[NE].v=v; edge[NE].w=w; - edge[NE].next=head[u]; head[u]=NE++; -} - -int d[MAXN]; -bool vis[MAXN]; -void SPFA(int n){ - for(int i=1; i<=n; ++i){ - d[i]=INF; vis[i]=0; - } - d[1]=0; vis[1]=1; - queue que; - que.push(1); - while(!que.empty()){ - int u=que.front(); que.pop(); - for(int i=head[u]; i!=-1; i=edge[i].next){ - int v=edge[i].v; - if(d[v]>d[u]+edge[i].w){ - d[v]=d[u]+edge[i].w; - if(!vis[v]){ - vis[v]=1; - que.push(v); - } - } - } - vis[u]=0; - } -} - -struct Node{ - int u,v,w; - bool operator<(const Node &nd)const{ - if(u==nd.u) return nd.vans_val){ - ans_val=b_val[b_rec[j]]; - ans_cnt=b_cnt[b_rec[j]]; - }else if(b_val[b_rec[j]]==ans_val){ - ans_cnt+=b_cnt[b_rec[j]]; - } - }else if(b_rec[j]ans_val){ - ans_val=b_val[b_rec[j]]+a_val[tmp]; - ans_cnt=b_cnt[b_rec[j]]*a_cnt[tmp]; - }else if(b_val[b_rec[j]]+a_val[tmp]==ans_val){ - ans_cnt+=b_cnt[b_rec[j]]*a_cnt[tmp]; - } - } - } - for(int j=0; j -#include -#include -#include -using namespace std; -#define INF (1LL<<60) -#define MAXN 55555 -#define MAXM 55555*2 - -struct Edge{ - int v,w,next; -}edge[MAXM]; -int NE,head[MAXN]; -void addEdge(int u,int v,int w){ - edge[NE].v=v; edge[NE].w=w; edge[NE].next=head[u]; - head[u]=NE++; -} - -long long d[MAXN]; -bool vis[MAXN]; -bool SPFA(int n){ - for(int i=1; i<=n; ++i){ - d[i]=INF; vis[i]=0; - } - d[1]=0; vis[1]=1; - queue que; - que.push(1); - while(!que.empty()){ - int u=que.front(); que.pop(); - for(int i=head[u]; i!=-1; i=edge[i].next){ - int v=edge[i].v; - if(d[v]>d[u]+edge[i].w){ - d[v]=d[u]+edge[i].w; - if(!vis[v]){ - vis[v]=1; - que.push(v); - } - } - } - vis[u]=0; - } - for(int i=1; i<=n; ++i){ - if(d[i]==INF) return 0; - } - return 1; -} - -int weight[MAXN]; -int main(){ - int t,n,m,a,b,c; - scanf("%d",&t); - while(t--){ - scanf("%d%d",&n,&m); - for(int i=1; i<=n; ++i){ - scanf("%d",weight+i); - } - NE=0; - memset(head,-1,sizeof(head)); - while(m--){ - scanf("%d%d%d",&a,&b,&c); - addEdge(a,b,c); - addEdge(b,a,c); - } - if(!SPFA(n)){ - puts("No Answer"); - continue; - } - long long ans=0; - for(int i=1; i<=n; ++i){ - ans+=d[i]*weight[i]; - } - printf("%lld\n",ans); - } - return 0; -} diff --git a/WABoss/POJ3368.cpp b/WABoss/POJ3368.cpp deleted file mode 100644 index b7dd3b90..00000000 --- a/WABoss/POJ3368.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -using namespace std; -#define MAXN 222222 - -int lrec[MAXN],rrec[MAXN]; - -int tree[MAXN<<2],N,x,y; -void update(int i,int j,int k){ - if(i==j){ - tree[k]=y; - return; - } - int mid=i+j>>1; - if(x<=mid) update(i,mid,k<<1); - else update(mid+1,j,k<<1|1); - tree[k]=max(tree[k<<1],tree[k<<1|1]); -} -int query(int i,int j,int k){ - if(x>y) return 0; - if(x<=i && j<=y){ - return tree[k]; - } - int mid=i+j>>1,res=0; - if(x<=mid) res=max(res,query(i,mid,k<<1)); - if(y>mid) res=max(res,query(mid+1,j,k<<1|1)); - return res; -} - -int seq[MAXN]; -int main(){ - int n,q,a,b; - while(~scanf("%d",&n) && n){ - scanf("%d",&q); - for(int i=1; i<=n; ++i){ - scanf("%d",seq+i); - } - seq[n+1]=111111; - - int rn=0; - lrec[0]=1; - for(int i=1; i<=n+1; ++i){ - if(seq[i]!=seq[i+1]){ - rrec[rn]=i; - rn++; - lrec[rn]=i+1; - } - } - - memset(tree,0,sizeof(tree)); - for(N=1; N=b){ - printf("%d\n",b-a+1); - continue; - } - res=max(rrec[i]-a+1,b-lrec[j]+1); - x=i+1; y=j-1; - res=max(res,query(0,N-1,1)); - printf("%d\n",res); - } - } - return 0; -} diff --git a/WABoss/POJ3411.cpp b/WABoss/POJ3411.cpp deleted file mode 100644 index 2ee05bdd..00000000 --- a/WABoss/POJ3411.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -using namespace std; -#define INF (1<<30) -#define MAXN 11 - -struct Edge{ - int v,c,p,r,next; -}edge[MAXN<<1]; -int NE,head[MAXN]; -void addEdge(int u,int v,int c,int p,int r){ - edge[NE].v=v; edge[NE].c=c; edge[NE].p=p; edge[NE].r=r; - edge[NE].next=head[u]; head[u]=NE++; -} - -struct Node{ - int u,s; - Node(int _u,int _s):u(_u),s(_s){} -}; - -int n,d[MAXN][1024]; -bool vis[MAXN][1024]; -int SPFA(){ - for(int i=0; i que; - que.push(Node(0,1)); - while(!que.empty()){ - int u=que.front().u,s=que.front().s; que.pop(); - for(int i=head[u]; i!=-1; i=edge[i].next){ - int v=edge[i].v; - int tmp=d[u][s]; - if(s>>edge[i].c&1){ - tmp+=edge[i].p; - }else{ - tmp+=edge[i].r; - } - if(d[v][s|(1<tmp){ - d[v][s|(1< -#include -#include -#include -using namespace std; -#define INF (1<<30) -#define MAXN 2555 -#define MAXM 2555*5555 - -struct Edge{ - int u,v,cap,cost,next; -}edge[MAXM]; -int head[MAXN]; -int NV,NE,vs,vt; - -void addEdge(int u,int v,int cap,int cost){ - edge[NE].u=u; edge[NE].v=v; edge[NE].cap=cap; edge[NE].cost=cost; - edge[NE].next=head[u]; head[u]=NE++; - edge[NE].u=v; edge[NE].v=u; edge[NE].cap=0; edge[NE].cost=-cost; - edge[NE].next=head[v]; head[v]=NE++; -} -bool vis[MAXN]; -int d[MAXN],pre[MAXN]; -bool SPFA(){ - for(int i=0;i que; - que.push(vs); - while(!que.empty()){ - int u=que.front(); que.pop(); - for(int i=head[u]; i!=-1; i=edge[i].next){ - int v=edge[i].v; - if(edge[i].cap && d[v]>d[u]+edge[i].cost){ - d[v]=d[u]+edge[i].cost; - pre[v]=i; - if(!vis[v]){ - vis[v]=1; - que.push(v); - } - } - } - vis[u]=0; - } - return d[vt]!=INF; -} -int MCMF(){ - int res=0; - while(SPFA()){ - int flow=INF,cost=0; - for(int u=vt; u!=vs; u=edge[pre[u]].u){ - flow=min(flow,edge[pre[u]].cap); - } - for(int u=vt; u!=vs; u=edge[pre[u]].u){ - edge[pre[u]].cap-=flow; - edge[pre[u]^1].cap+=flow; - cost+=flow*edge[pre[u]].cost; - } - res+=cost; - } - return res; -} - -int main(){ - int t,n,m,a; - scanf("%d",&t); - while(t--){ - scanf("%d%d",&n,&m); - vs=n*m+n; vt=vs+1; NV=vt+1; NE=0; - memset(head,-1,sizeof(head)); - for(int i=0; i -#include -using namespace std; -#define MOD 1000000000000000000LL - -struct Num{ - unsigned long long a[11]; - bool flag; - Num(int n=0){ - memset(a,0,sizeof(a)); - a[0]=n; - flag=0; - } - Num operator+(const Num &n) const { - Num res; - unsigned long long carry=0; - for(int i=0; i<11; ++i){ - unsigned long long tmp=a[i]+n.a[i]+carry; - res.a[i]=tmp%MOD; - carry=tmp/MOD; - } - return res; - } -}; -void output(Num n){ - int i=10; - while(i>=0 && n.a[i]==0) --i; - if(i==-1){ - puts("0"); - return; - } - printf("%llu",n.a[i]); - while(i>0){ - --i; - printf("%018llu",n.a[i]); - } - putchar('\n'); -} - -int dx[]={0,0,1,-1}; -int dy[]={1,-1,0,0}; - -int n,a[22][22]; -Num d[22][22][55]; - -Num dp(int x,int y,int t){ - if(x==0 && y==0 && t==0) return Num(1); - if(t==0) return Num(0); - if(d[x][y][t].flag) return d[x][y][t]; - Num res; - for(int i=0; i<4; ++i){ - int nx=x+dx[i],ny=y+dy[i]; - if(nx<0 || nx>=n || ny<0 || ny>=n || a[nx][ny]) continue; - res=res+dp(nx,ny,t-1); - } - d[x][y][t]=res; - d[x][y][t].flag=1; - return d[x][y][t]; -} - -int main(){ - int k; - while(~scanf("%d%d",&n,&k)){ - for(int i=0; i -#include -#include -using namespace std; -#define MAXN 55555 - -struct Edge{ - int v,w,next; -}edge[MAXN<<1]; -int NE,head[MAXN]; -void addEdge(int u,int v,int w){ - edge[NE].v=v; edge[NE].w=w; edge[NE].next=head[u]; - head[u]=NE++; -} - -int dep[MAXN],weight[MAXN],par[17][MAXN]; -void dfs(int u,int fa,int w){ - weight[u]=w; - for(int i=head[u]; i!=-1; i=edge[i].next){ - int v=edge[i].v; - if(v==fa) continue; - dep[v]=dep[u]+1; - par[0][v]=u; - dfs(v,u,w+edge[i].w); - } -} - -void init(int n){ - dfs(0,0,0); - for(int i=1; i<17; ++i){ - for(int j=0; jdep[v]) swap(u,v); - for(int k=0; k<17; ++k){ - if(dep[v]-dep[u]>>k&1){ - v=par[k][v]; - } - } - if(v==u) return u; - for(int k=16; k>=0; --k){ - if(par[k][u]!=par[k][v]){ - u=par[k][u]; - v=par[k][v]; - } - } - return par[0][u]; -} - -int calc(int u,int v){ - return weight[u]+weight[v]-2*weight[lca(u,v)]; -} - -int main(){ - int n,q,a,b,c; - bool flag=0; - while(~scanf("%d",&n)){ - NE=0; - memset(head,-1,sizeof(head)); - for(int i=1; i>1); - } - } - return 0; -} diff --git a/Wonter/Codeforces/Codeforces Round #352 (Div. 2) b/Wonter/Codeforces/Codeforces Round #352 (Div. 2) deleted file mode 100644 index d17d279e..00000000 --- a/Wonter/Codeforces/Codeforces Round #352 (Div. 2) +++ /dev/null @@ -1,156 +0,0 @@ -//C. Recycling Bottles - -#include -using namespace std; - -vector > fir; -vector > sec; -pair<__int64, __int64> a; -pair<__int64, __int64> b; -pair<__int64, __int64> t; -pair<__int64, __int64> p[100500]; -double DisTance(pair<__int64, __int64> x, pair<__int64, __int64> y) -{ - return sqrt((x.first - y.first)*(x.first - y.first) + (x.second - y.second)*(x.second - y.second)); -} -int main() -{ - __int64 n; - scanf("%I64d%I64d", &a.first, &a.second); - scanf("%I64d%I64d", &b.first, &b.second); - scanf("%I64d%I64d", &t.first, &t.second); - scanf("%I64d", &n); - for(__int64 i = 1; i <= n; ++i) - scanf("%I64d%I64d", &p[i].first, &p[i].second); - if(n == 1) - { - double ans; - ans = min(DisTance(a, p[1]) + DisTance(p[1], t), DisTance(b, p[1]) + DisTance(p[1], t)); - printf("%f\n", ans); - return 0; - } - for(__int64 i = 1; i <= n; ++i) - { - fir.push_back(make_pair(DisTance(p[i], t) - DisTance(a, p[i]), i)); - sec.push_back(make_pair(DisTance(p[i], t) - DisTance(b, p[i]), i)); - } - sort(fir.begin(), fir.end(), greater >()); - sort(sec.begin(), sec.end(), greater >()); - __int64 chooseFir, chooesSec; - chooesSec = chooseFir = -1; - double maxDis = 0; - bool chooes = false; - for(auto ele : fir) - { - if(chooes == false || ele.first > maxDis) - { - chooseFir = ele.second; - chooesSec = -1; - maxDis = ele.first; - chooes = true; - break; - } - } - for(auto ele : sec) - { - if(chooes == false || ele.first > maxDis) - { - chooseFir = -1; - chooesSec = ele.second; - maxDis = ele.first; - chooes = true; - break; - } - } - for(auto eleA : fir) - { - for(auto eleB : sec) - { - if(eleB.second != eleA.second) - { - if(chooes == false || eleA.first + eleB.first > maxDis) - { - maxDis = eleA.first + eleB.first; - chooseFir = eleA.second; - chooesSec = eleB.second; - chooes = true; - } - break; - } - } - } - double ans = 0.0; - for(__int64 i = 1; i <= n; ++i) - { - if(i == chooseFir) - ans += DisTance(a, p[i]) + DisTance(p[i], t); - else if(i == chooesSec) - ans += DisTance(b, p[i]) + DisTance(p[i], t); - else - ans += 2 * DisTance(p[i], t); - } - printf("%f\n", ans); - return 0; -} - - -//D. Robin Hood -#include -using namespace std; - -__int64 arr[500400]; -__int64 n, k; -__int64 GetMin() -{ - __int64 left, right; - __int64 sum = 0; - for(__int64 i = 1; i <= n; ++i) - sum += arr[i]; - left = *min_element(arr + 1, arr + 1 + n); - right = sum / n; - while(left < right) - { - __int64 mid = left + ((right - left + 1) >> 1); - __int64 t = 0; - for(__int64 i = 1; i <= n; ++i) - if(arr[i] < mid) - t += mid - arr[i]; - if(t <= k) - left = mid; - else - right = mid - 1; - } - return left; -} -__int64 GetMax() -{ - __int64 left, right; - __int64 sum = 0; - for(__int64 i = 1; i <= n; ++i) - sum += arr[i]; - left = (sum + n - 1) / n; - right = *max_element(arr + 1, arr + 1 + n); - while(left < right) - { - __int64 mid = left + ((right - left) >> 1); - __int64 t = 0; - for(__int64 i = 1; i <= n; ++i) - if(arr[i] > mid) - t += arr[i] - mid; - if(t <= k) - right = mid; - else - left = mid + 1; - } - return left; -} -int main() -{ - scanf("%I64d%I64d", &n, &k); - for(__int64 i = 1; i <= n; ++i) - scanf("%I64d", &arr[i]); - __int64 maxn = GetMax(); - __int64 minn = GetMin(); - printf("%I64d\n", maxn - minn); - return 0; -} diff --git a/Wonter/Lightoj/1108.cpp b/Wonter/Lightoj/1108.cpp deleted file mode 100644 index cbc338d1..00000000 --- a/Wonter/Lightoj/1108.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -using namespace std; - -typedef pair P; -vector

edge[1200]; -vector ans; -int mindis[1200]; -bool inQue[1200]; -int toCycle[1200]; -int updated[1200]; -int n, m; - -void Dfs(int cur) -{ - ans.push_back(cur); - toCycle[cur] = true; - for(int i = 0; i < static_cast(edge[cur].size()); ++i) - { - P next = edge[cur][i]; - if(!toCycle[next.first]) - Dfs(next.first); - } -} -bool Spfa() -{ - ans.clear(); - memset(mindis, 0, sizeof(mindis)); - memset(updated, 0, sizeof(updated)); - queue que; - for(int i = 0; i < n; ++i) - que.push(i); - memset(inQue, true, sizeof(inQue)); - while(que.size()) - { - int now = que.front(); - que.pop(); - inQue[now] = false; - if(updated[now] > n) - { - if(!toCycle[now]) - Dfs(now); - continue; - } - for(int i = 0; i < static_cast(edge[now].size()); ++i) - { - P next = edge[now][i]; - if(next.second + mindis[now] < mindis[next.first]) - { - mindis[next.first] = next.second + mindis[now]; - if(!inQue[next.first]) - { - inQue[next.first] = true; - que.push(next.first); - } - ++updated[next.first]; - } - } - } - return !ans.empty(); -} -int main() -{ - int _case = 1; - int T; - scanf("%d", &T); - while(T--) - { - memset(edge, 0, sizeof(edge)); - memset(toCycle, false, sizeof(toCycle)); - scanf("%d%d", &n, &m); - for(int i = 1; i <= m; ++i) - { - int u, v, w; - scanf("%d%d%d", &u, &v, &w); - edge[v].push_back(make_pair(u, w)); - } - printf("Case %d: ", _case++); - if(Spfa()) - { - sort(ans.begin(), ans.end()); - for(int i = 0; i < static_cast(ans.size()); ++i) - { - if(i) - printf(" "); - printf("%d", ans[i]); - } - } - else - printf("impossible"); - printf("\n"); - } - return 0; -} diff --git a/Wonter/Lightoj/1123.cpp b/Wonter/Lightoj/1123.cpp deleted file mode 100644 index 3f982633..00000000 --- a/Wonter/Lightoj/1123.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include -using namespace std; - -struct Edge -{ - int u, v, w; - int vis; - friend bool operator < (Edge a, Edge b) - { - if(a.w == b.w) - return a.vis < b.vis; - return a.w < b.w; - } - Edge(int a, int b, int c, int d) - { - u = a; - v = b; - w = c; - vis = d; - } -}; -set edges; -int fa[300]; -int n, m; -void Init() -{ - for(int i = 1;i <= n;++i) - fa[i] = i; -} -int Find(int x) -{ - if(fa[x] == x) - return x; - return fa[x] = Find(fa[x]); -} -bool Same(int u, int v) -{ - return Find(u) == Find(v); -} -void Unite(int u, int v) -{ - u = Find(u); - v = Find(v); - if(u == v) - return ; - fa[v] = u; -} -int Krusal() -{ - int cnt = 0; - int ret = 0; - Init(); - for(set::iterator it = edges.begin(); it != edges.end(); ++it) - { - Edge ele = *it; - if(!Same(ele.u, ele.v)) - { - Unite(ele.u, ele.v); - ret += ele.w; - ++cnt; - } - if(cnt == n - 1) - break; - } - if(cnt != n - 1) - return -1; - return ret; -} -int main() -{ - int T, _case = 1; - scanf("%d", &T); - while(T--) - { - edges.clear(); - scanf("%d%d", &n, &m); - printf("Case %d:\n", _case++); - for(int i = 1;i <= m;++i) - { - int u, v, w; - scanf("%d%d%d", &u, &v, &w); - edges.insert(Edge(u, v, w, i)); - printf("%d\n", Krusal()); - } - } - return 0; -} diff --git a/Wonter/Lightoj/1126.cpp b/Wonter/Lightoj/1126.cpp deleted file mode 100644 index 7715c3fb..00000000 --- a/Wonter/Lightoj/1126.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -using namespace std; - -int arr[60]; -int dp[2][500002]; -int main() -{ - int T, _case = 1; - scanf("%d", &T); - while(T--) - { - memset(dp, -1, sizeof(dp)); - int n; - int sum = 0; - scanf("%d", &n); - for(int i = 1; i <= n; ++i) - { - scanf("%d", &arr[i]); - sum += arr[i]; - } - dp[0][0] = 0; - for(int i = 1; i <= n; ++i) - { - for(int j = 0; j <= sum; ++j) - { - dp[i & 1][j] = dp[(i - 1) & 1][j]; - if(j + arr[i] <= sum && dp[(i - 1) & 1][j + arr[i]] != -1) - dp[i & 1][j] = max(dp[i & 1][j], dp[(i - 1) & 1][j + arr[i]]); - if(arr[i] - j >= 0 && dp[(i - 1) & 1][arr[i] - j] != -1) - dp[i & 1][j] = max(dp[i & 1][j], j + dp[(i - 1) & 1][arr[i] - j]); - if(j - arr[i] >= 0 && dp[(i - 1) & 1][j - arr[i]] != -1) - dp[i & 1][j] = max(dp[i & 1][j], dp[(i - 1) & 1][j - arr[i]] + arr[i]); - } - } - if(dp[n & 1][0] == -1 || dp[n & 1][0] == 0) - printf("Case %d: impossible\n", _case++); - else - printf("Case %d: %d\n", _case++, dp[n & 1][0]); - } - return 0; -} diff --git a/Wonter/Lightoj/1129.cpp b/Wonter/Lightoj/1129.cpp deleted file mode 100644 index fbc89329..00000000 --- a/Wonter/Lightoj/1129.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -using namespace std; -set st; -string str[10050]; -int main() -{ - int T; - int _case = 1; - scanf("%d", &T); - while(T--) - { - st.clear(); - int n; - scanf("%d", &n); - bool flag = false; - for(int i = 1; i <= n; ++i) - { - cin >> str[i]; - st.insert(str[i]); - } - for(int i = 1; i <= n; ++i) - { - for(string::size_type j = 0; j < str[i].length(); ++j) - { - if(st.find(str[i].substr(0, j)) != st.end()) - flag = true; - if(flag) - break; - } - if(flag) - break; - } - if(flag) - printf("Case %d: NO\n", _case++); - else - printf("Case %d: YES\n", _case++); - } - return 0; -} diff --git a/YgBnFg/NEU1694 b/YgBnFg/NEU1694 deleted file mode 100644 index 985a2edd..00000000 --- a/YgBnFg/NEU1694 +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 10000000 -#define Mm 670000 -#define MM 1e14+5 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -int prime[Mm],tot=0,no[Mn]; -int a; -vector > vt; -int ans[Mn]; -void Prime() { - vt.push_back(make_pair(1,1)); - for(int i=2;i<=Mn;i++) { - if(!no[i]) { - prime[++tot]=i; - for(double j=(double)i*i;j>1; - if(vt[mid].first>n) { - r=mid-1; - } else l=mid; - } - printf("Case %d: %d\n",cas,ans[r]); - } -} diff --git a/YgBnFg/cf352div2c b/YgBnFg/cf352div2c deleted file mode 100644 index fe08a999..00000000 --- a/YgBnFg/cf352div2c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 200010 -#define Mm 2000005 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -#define eps 1e-10 -int a[Mn],b[Mn]; -struct node { - double dis; - int i; - node(){} - node(double dis,int i):dis(dis),i(i){} - bool operator <(const node x) const { - if(x.dis-dis<0) return 0; - return 1; - } -}pa[Mn],pb[Mn]; -double getdis(double x,double y,double c,double d) { - return sqrt((x-c)*(x-c)+(y-d)*(y-d)); -} -double dis[Mn]; -int main() { - int x1,y1,x2,y2,t1,t2; - int n; - scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&t1,&t2); - double ans=0.0; - double disa=getdis(x1,y1,t1,t2); - double disb=getdis(x2,y2,t1,t2); - scanf("%d",&n); - for(int i=0;ipa[pos].dis+pb[pos-1].dis) { - ans3=ans-pb[pos].dis-pa[pos-1].dis; - } else { - ans3=ans-pa[pos].dis-pb[pos-1].dis; - } - } else { - ans3=ans-pa[pos].dis-pb[pos].dis; - } - printf("%.10f\n",min(ans1,min(ans2,ans3))); - return 0; -} diff --git a/YgBnFg/cf352div2d b/YgBnFg/cf352div2d deleted file mode 100644 index a397727e..00000000 --- a/YgBnFg/cf352div2d +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 500010 -#define Mm 2000005 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -int a[Mn],n,k; -bool xia(int x) { - ll lsum=0; - for(int i=0;ik) return false; - return true; -} -bool da(int x) { - ll sssum=0; - for(int i=0;ix) sssum+=(a[i]-x); - } - if(sssum>k) return false; - return true; -} -int main() { - scanf("%d%d",&n,&k); - ll sum=0; - for(int i=0;i>1; - if(xia(mid)) { - l=mid; - } else r=mid-1; - } - ans1=l; - l=1,r=1e9; - int ans2; - while(l>1; - if(da(mid)) { - r=mid; - } else l=mid+1; - } - ans2=r; - //cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 400 -#define Mm 20005 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -struct edge { - int v,next; -}e[Mm]; -int tot,head[Mn]; -void addedge(int u,int v) { - e[tot].v=v; - e[tot].next=head[u]; - head[u]=tot++; -} -int cnt,pre[Mn]; -int findpre(int x) { - return x==pre[x]?pre[x]:pre[x]=findpre(pre[pre[x]]); -} -void ol(int a,int b) { - a=findpre(a); - b=findpre(b); - if(a!=b) pre[a]=b; -} -int lk[Mn],vis[Mn],mark[Mn],match[Mn],ne[Mn]; -int lca(int x,int y) { - static int t=0;t++; - while(1) { - if(x!=-1) { - x=findpre(x); - if(vis[x]==t) return x; - vis[x]=t; - if(match[x]!=-1) x=ne[match[x]]; - else x=-1; - } - swap(x,y); - } - -} -queue q; -void group(int a,int p) { - while(a!=p) { - int b=match[a],c=ne[b]; - if(findpre(c)!=p) ne[c]=b; - if(mark[b]==2) mark[b]=1,q.push(b); - if(mark[c]==2) mark[c]=1,q.push(c); - ol(a,b),ol(b,c); - a=c; - } -} -void aug(int s) { - for(int i=0;i<=cnt;i++) { - ne[i]=-1; - pre[i]=i; - mark[i]=0; - vis[i]=-1; - } - mark[s]=1; - while(!q.empty()) q.pop(); - q.push(s); - while((!q.empty())&&match[s]==-1) { - int u=q.front(); - q.pop(); - for(int i=head[u];~i;i=e[i].next) { - int v=e[i].v; - if(match[u]==v||findpre(u)==findpre(v)||mark[v]==2) continue; - if(mark[v]==1) { - int r=lca(u,v); - if(findpre(u)!=r) ne[u]=v; - if(findpre(v)!=r) ne[v]=u; - group(u,r); - group(v,r); - } else if(match[v]==-1) { - ne[v]=u; - for(int x=v;~x;) { - int y=ne[x]; - int mv=match[y]; - match[x]=y,match[y]=x; - x=mv; - } - break; - } else { - ne[v]=u; - q.push(match[v]); - mark[match[v]]=1; - mark[v]=2; - } - } - } -} -int mp[Mn][Mn],num[Mn][Mn]; -void init() { - tot=0;cnt=0; - CLR(mp,0); - CLR(head,-1); - CLR(num,0); -} -int way[20][2]={-2,-2,-2,-1,-2,1,-2,2,-1,-2,-1,-1,-1,0,-1,1,-1,2,0,-1,0,1,1,-2,1,-1,1,0,1,1,1,2,2,-2,2,-1,2,1,2,2}; -int main() { - int t,n,m,kx,ky; - char s[Mn]; - scanf("%d",&t); - for(int cas=1;cas<=t;cas++) { - scanf("%d%d",&n,&m); - init(); - for(int i=0;i=n||y<0||y>=m||(x==kx&&y==ky)||!num[x][y]) continue; - int u=num[i][j],v=num[x][y]; - if(!mp[u][v]) { - addedge(u,v); - addedge(v,u); - mp[u][v]=mp[v][u]=1; - } - } - } - } - for(int i=1;i<=cnt;i++) match[i]=-1; - for(int i=1;i<=cnt;i++) { - if(match[i]==-1) { - aug(i); - } - } - for(int k=0;k<20;k++) { - int x=kx+way[k][0]; - int y=ky+way[k][1]; - if(x<0||x>=n||y<0||y>=m||!num[x][y]) continue; - int u=num[kx][ky],v=num[x][y]; - addedge(u,v); - addedge(v,u); - } - aug(num[kx][ky]); - printf("Case #%d: ",cas); - if(match[num[kx][ky]]==-1) printf("daizhenyang lose\n"); - else printf("daizhenyang win\n"); - } - return 0; -} diff --git a/YgBnFg/hdu3551 b/YgBnFg/hdu3551 deleted file mode 100644 index 8cea241e..00000000 --- a/YgBnFg/hdu3551 +++ /dev/null @@ -1,187 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 810 -#define Mm 200005 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -struct edge { - int v,next; -}e[Mm]; -int tot,head[Mn]; -void addedge(int u,int v) { - e[tot].v=v; - e[tot].next=head[u]; - head[u]=tot++; -} -int cnt,pre[Mn]; -int findpre(int x) { - return x==pre[x]?pre[x]:pre[x]=findpre(pre[pre[x]]); -} -void ol(int a,int b) { - a=findpre(a); - b=findpre(b); - if(a!=b) pre[a]=b; -} -int lk[Mn],vis[Mn],mark[Mn],match[Mn],ne[Mn]; -int lca(int x,int y) { - static int t=0;t++; - while(1) { - if(x!=-1) { - x=findpre(x); - if(vis[x]==t) return x; - vis[x]=t; - if(match[x]!=-1) x=ne[match[x]]; - else x=-1; - } - swap(x,y); - } - -} -queue q; -void group(int a,int p) { - while(a!=p) { - int b=match[a],c=ne[b]; - if(findpre(c)!=p) ne[c]=b; - if(mark[b]==2) mark[b]=1,q.push(b); - if(mark[c]==2) mark[c]=1,q.push(c); - ol(a,b),ol(b,c); - a=c; - } -} -void aug(int s) { - for(int i=0;i<=cnt;i++) { - ne[i]=-1; - pre[i]=i; - mark[i]=0; - vis[i]=-1; - } - mark[s]=1; - while(!q.empty()) q.pop(); - q.push(s); - while((!q.empty())&&match[s]==-1) { - int u=q.front(); - q.pop(); - for(int i=head[u];~i;i=e[i].next) { - int v=e[i].v; - if(match[u]==v||findpre(u)==findpre(v)||mark[v]==2) continue; - if(mark[v]==1) { - int r=lca(u,v); - if(findpre(u)!=r) ne[u]=v; - if(findpre(v)!=r) ne[v]=u; - group(u,r); - group(v,r); - } else if(match[v]==-1) { - ne[v]=u; - for(int x=v;~x;) { - int y=ne[x]; - int mv=match[y]; - match[x]=y,match[y]=x; - x=mv; - } - break; - } else { - ne[v]=u; - q.push(match[v]); - mark[match[v]]=1; - mark[v]=2; - } - } - } -} -int degree[Mn]; -int d[Mn]; -int U[Mn],V[Mn]; -int id[Mn],num[Mn]; -void init() { - tot=0;cnt=1; - CLR(head,-1); - CLR(id,0); - CLR(degree,0); -} -void build(int n,int m) { - for(int i=1;i<=m;i++) { - int u=U[i],v=V[i]; - if(!id[u]) { - id[u]=cnt; - num[u]=cnt+d[u]-1; - cnt+=d[u]; - } - if(!id[v]) { - id[v]=cnt; - num[v]=cnt+d[v]-1; - cnt+=d[v]; - } - if(!id[n+i+1]) { - id[n+i+1]=cnt; - num[n+i+1]=cnt+1; - cnt+=2; - } - int t=id[n+i+1]; - addedge(t,t+1); - addedge(t+1,t); - for(int j=id[u];j<=num[u];j++) - addedge(t,j),addedge(j,t); - for(int j=id[v];j<=num[v];j++) - addedge(t+1,j),addedge(j,t+1); - } -} -int main() { - int t; - scanf("%d",&t); - for(int cas=1;cas<=t;cas++) { - int n,m;init(); - scanf("%d%d",&n,&m); - for(int i=1;i<=m;i++) { - scanf("%d%d",&U[i],&V[i]); - degree[U[i]]++; - degree[V[i]]++; - } - int flag=1; - for(int i=1;i<=n;i++) { - scanf("%d",&d[i]); - if(degree[i] -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 30010 -#define Mm 150005 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -int dis[Mn]; -int vis[Mn]; -int n,m; -struct edge { - int v,w,next; -}e[Mm]; -int tot,head[Mn]; -struct node { - int v; - int cost; - node(int v,int cost) : v(v),cost(cost) {}; - bool operator <(const node x) const { - return cost>x.cost; - } -}; -void addedge(int u,int v,int w) { - e[tot].v=v; - e[tot].w=w; - e[tot].next=head[u];; - head[u]=tot++; -} -void dijkstra(int st) { - priority_queue q; - CLR(dis,0x3f); - CLR(vis,0); - dis[st]=0; - q.push(node(st,0)); - while(!q.empty()) { - node tmp=q.top(); - q.pop(); - int u=tmp.v; - if(vis[u]) continue; - vis[u]=1; - for(int i=head[u]; i!=-1; i=e[i].next) { - int v=e[i].v; - int cost=e[i].w; - if(!vis[v]&&dis[v]>dis[u]+cost) { - dis[v]=dis[u]+cost; - q.push(node(v,dis[v])); - } - } - } -} -void init() { - tot=0; - CLR(head,-1); -} -int main() { - int n,m; - while(~scanf("%d%d",&n,&m)) { - init(); - for(int i=1;i<=m;i++) { - int u,v,w; - scanf("%d%d%d",&u,&v,&w); - addedge(u,v,w); - } - dijkstra(1); - printf("%d\n",dis[n]); - } - return 0; -} diff --git a/YgBnFg/zoj3316.cpp b/YgBnFg/zoj3316.cpp deleted file mode 100644 index 7da2aa7f..00000000 --- a/YgBnFg/zoj3316.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INF 0x3f3f3f3f -#define Mn 400 -#define Mm 200005 -#define mod 1000000007 -#define CLR(a,b) memset((a),(b),sizeof((a))) -#define CPY(a,b) memcpy ((a), (b), sizeof((a))) -#pragma comment(linker, "/STACK:102400000,102400000") -#define ul u<<1 -#define ur (u<<1)|1 -using namespace std; -typedef long long ll; -struct edge { - int v,next; -}e[Mm]; -struct point { - int x,y; -}p[Mn]; -int dis(point a,point b) { - return abs(a.x-b.x)+abs(a.y-b.y); -} -int tot,head[Mn]; -void addedge(int u,int v) { - e[tot].v=v; - e[tot].next=head[u]; - head[u]=tot++; -} -int pre[Mn]; -int findpre(int x) { - return x==pre[x]?pre[x]:pre[x]=findpre(pre[pre[x]]); -} -void ol(int a,int b) { - a=findpre(a); - b=findpre(b); - if(a!=b) pre[a]=b; -} -int n,lk[Mn],vis[Mn],mark[Mn],match[Mn],ne[Mn]; -int lca(int x,int y) { - static int t=0;t++; - while(1) { - if(x!=-1) { - x=findpre(x); - if(vis[x]==t) return x; - vis[x]=t; - if(match[x]!=-1) x=ne[match[x]]; - else x=-1; - } - swap(x,y); - } - -} -queue q; -void group(int a,int p) { - while(a!=p) { - int b=match[a],c=ne[b]; - if(findpre(c)!=p) ne[c]=b; - if(mark[b]==2) mark[b]=1,q.push(b); - if(mark[c]==2) mark[c]=1,q.push(c); - ol(a,b),ol(b,c); - a=c; - } -} -void aug(int s) { - for(int i=0;i<=n;i++) { - ne[i]=-1; - pre[i]=i; - mark[i]=0; - vis[i]=-1; - } - mark[s]=1; - while(!q.empty()) q.pop(); - q.push(s); - while((!q.empty())&&match[s]==-1) { - int u=q.front(); - q.pop(); - for(int i=head[u];~i;i=e[i].next) { - int v=e[i].v; - if(match[u]==v||findpre(u)==findpre(v)||mark[v]==2) continue; - if(mark[v]==1) { - int r=lca(u,v); - //cout< -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -#define INF 0x3f3f3f3f -#define PI acos(-1.0) -#define N 210 - -int s1[110]; -int s2[110]; -int flag[110]; -char a1[110]; -char a2[110]; - -int sushu(int n) -{ - int m=sqrt(n); - int ff=0; - for(int i=2;i<=m;i++) - { - if(n%i==0) - { - ff=1; - break; - } - } - if(ff) - return 0; - return 1; -} - -void init() -{ - int ff=0; - for(int i=2;i<=100000;i++) - { - if(sushu(i)) - { - flag[ff++]=i; - if(ff>102) - break; - } - } -} -void debug() -{ - for(int i=0;i<=100;i++) - printf("%d\n",flag[i]); -} - -int main() -{ - init(); - // debug(); - while(1) - { - int x; - int xx; - int len1,len2; - len1=len2=0; - memset(s1,0,sizeof(s1)); - memset(s2,0,sizeof(s2)); - while(scanf("%d",&x)) - { - xx=getchar(); - s1[len1++]=x; - if(xx==' ') - break; - } - while(scanf("%d",&x)) - { - xx=getchar(); - s2[len2++]=x; - if(xx=='\n') - break; - } - int qq=0; - memset(a1,0,sizeof(a1)); - memset(a2,0,sizeof(a2)); - for(int i=len1-1;i>=0;i--) - { - a1[qq++]=s1[i]; - } - len1=qq; - qq=0; - for(int i=len2-1;i>=0;i--) - { - a2[qq++]=s2[i]; - } - len2=qq; - if(len1==1&&len2==1&&a1[0]==0&&a2[0]==0) - break; - int ans[110]; - memset(ans,0,sizeof(ans)); - int gg; - int num=0; - int flat=0; - for(int i=0;i=flag[i]) - { - flat=1; - } - else - flat=0; - ans[num++]=gg%flag[i]; - } - if(flat) - { - ans[num++]=1; - } - printf("%d",ans[num-1]); - for(int i=num-2;i>=0;i--) - { - printf(",%d",ans[i]); - } - printf("\n"); - } - return 0; -} - - - diff --git "a/ZZBoom/HK\347\256\227\346\263\225\346\250\241\346\235\277\357\274\210HUST2604\357\274\211" "b/ZZBoom/HK\347\256\227\346\263\225\346\250\241\346\235\277\357\274\210HUST2604\357\274\211" deleted file mode 100644 index 901a5138..00000000 --- "a/ZZBoom/HK\347\256\227\346\263\225\346\250\241\346\235\277\357\274\210HUST2604\357\274\211" +++ /dev/null @@ -1,119 +0,0 @@ -//http://begin.lydsy.com/JudgeOnline/problem.php?id=2604 - -#include -#include -#include -#include -#include -#include -using namespace std; - -const int N = 300010; -const int MAXM = 300010; -const int INF = 0x3f3f3f3f; - -int dist[N<<1],mx[N],my[N],m,n; -vector mp[N]; -int que[N<<1],head,tail; -int bfs() -{ - int i; - head=0; - tail=-1; - for(i=1; i<=n; i++) - if(mx[i]==-1) que[++tail]=i; - for(i=0; i<=m+n; i++) dist[i]=0; - int flag=0; - while(head<=tail) - { - int u=que[head++]; - for(i=0; i -inline bool scan_d(T &ret) -{ - char c; - int sgn; - if(c=getchar(),c==EOF) return 0; //EOF - while(c!='-'&&(c<'0'||c>'9')) c=getchar(); - sgn=(c=='-')?-1:1; - ret=(c=='-')?0:(c-'0'); - while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); - ret*=sgn; - return 1; -} -inline void out(int x) -{ - if(x>9) out(x/10); - putchar(x%10+'0'); -} - -int main() -{ - //int n,m; - //scanf("%d%d",&n,&m); - scan_d(n); - scan_d(m); - int u,v; - for(int i=0; i -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -#define INF 0x3f3f3f3f -#define PI acos(-1.0) -#define N 100010 - -int dfn[N]; -int low[N]; -int stap[N]; -int vis[N]; -int in[N]; -int tp,p,cnt; -int kc[N]; -int kr[N]; -int n; -struct asd{ - int to; - int next; -}; -asd q[N]; -int head[N],tol; - -void tarjan(int u) -{ - dfn[u]=low[u]=++tp; - stap[++p]=u; - vis[u]=1; - for(int k=head[u];k!=-1;k=q[k].next) - { - int x=q[k].to; - if(!dfn[x]) - { - tarjan(x); - low[u]=min(low[u],low[x]); - } - else if(vis[x]) - { - low[u]=min(low[u],dfn[x]); - } - } - if(dfn[u]==low[u]) - { - cnt++; - int temp; - while(1) - { - temp=stap[p]; - vis[temp]=0; - p--; - if(temp==u) - break; - } - } -} - - -void init() -{ - memset(vis,0,sizeof(vis)); - memset(dfn,0,sizeof(dfn)); - - memset(head,-1,sizeof(head)); - tol=0; -} - -void add(int a,int b) -{ - q[tol].to=b; - q[tol].next=head[a]; - head[a]=tol++; -} - -int main() -{ - int m; - while(~scanf("%d%d",&n,&m)) - { - if(n==0&&m==0) - break; - - init(); - for(int i=1;i<=m;i++) - { - int a,b; - scanf("%d%d",&a,&b); - add(a,b); - } - - tp=p=cnt=0; - for(int i=1;i<=n;i++) - { - if(!dfn[i]) - { - tarjan(i); - } - } - if(cnt==1) - { - printf("Yes\n"); - } - else - { - printf("No\n"); - } - } - return 0; -} - diff --git "a/ZZBoom/\345\233\276\347\232\204\345\274\272\350\277\236\351\200\232NO.2" "b/ZZBoom/\345\233\276\347\232\204\345\274\272\350\277\236\351\200\232NO.2" deleted file mode 100644 index 33438fcd..00000000 --- "a/ZZBoom/\345\233\276\347\232\204\345\274\272\350\277\236\351\200\232NO.2" +++ /dev/null @@ -1,143 +0,0 @@ -//poj-1236 -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -#define INF 0x3f3f3f3f -#define PI acos(-1.0) -#define N 110 - -int ma[N][N]; -int dfn[N]; -int low[N]; -int stap[N]; -int vis[N]; -int in[N]; -int tp,p,cnt; -int kc[N]; -int kr[N]; -int n; - -void tarjan(int u) -{ - dfn[u]=low[u]=++tp; - stap[++p]=u; - vis[u]=1; - for(int i=1;i<=n;i++) - { - if(!ma[u][i]) - continue; - if(!dfn[i]) - { - tarjan(i); - low[u]=min(low[u],low[i]); - } - else if(vis[i]) - { - low[u]=min(low[u],dfn[i]); - } - } - if(dfn[u]==low[u]) - { - cnt++; - int temp; - while(1) - { - temp=stap[p]; - vis[temp]=0; - in[temp]=cnt; - p--; - if(temp==u) - { - break; - } - } - } -} - -void fun() -{ - int pc,pr; - - memset(kc,0,sizeof(kc)); - memset(kr,0,sizeof(kr)); - - for(int i=1;i<=n;i++) - { - for(int j=1;j<=n;j++) - { - if(ma[i][j]&&in[i]!=in[j]) - { - kr[in[j]]++; - kc[in[i]]++; - } - } - } - - pc=pr=0; - for(int i=1;i<=cnt;i++) - { - if(!kr[i]) - { - pr++; - } - if(!kc[i]) - { - pc++; - } - } - if(cnt==1) - { - printf("1\n0\n"); - } - else - printf("%d\n%d\n",pr,max(pr,pc)); -} - -void init() -{ - memset(ma,0,sizeof(ma)); - memset(vis,0,sizeof(vis)); - memset(dfn,0,sizeof(dfn)); -} - -int main() -{ - while(~scanf("%d",&n)) - { - int x; - init(); - for(int i=1;i<=n;i++) - { - while(scanf("%d",&x)&&x) - ma[i][x]=1; - } - //找强连通分量 - tp=p=cnt=0; - for(int i=1;i<=n;i++) - { - if(!dfn[i]) - { - tarjan(i); - } - } - fun(); - } - return 0; -} -/* - -5 -2 4 3 0 -4 5 0 -0 -0 -1 0 - - -*/ diff --git "a/ZZBoom/\345\233\276\347\232\204\345\274\272\350\277\236\351\200\232NO.3" "b/ZZBoom/\345\233\276\347\232\204\345\274\272\350\277\236\351\200\232NO.3" deleted file mode 100644 index e976e9fc..00000000 --- "a/ZZBoom/\345\233\276\347\232\204\345\274\272\350\277\236\351\200\232NO.3" +++ /dev/null @@ -1,142 +0,0 @@ -//强连通缩点,求出度和入度较大值 -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -#define PI acos(-1.0) -#define N 20010 - -struct asd{ - int to; - int next; -}; -asd q[N*3]; -int head[N*3]; -int tol; - -int low[N]; -int dfn[N]; -int vis[N]; -int stap[N]; -int in[N]; -int kr[N]; -int kc[N]; -int tp,p; -int cnt; -int n; - -void tarjan(int u) -{ - dfn[u]=low[u]=++tp; - stap[++p]=u; - vis[u]=1; - for(int i=head[u];i!=-1;i=q[i].next) - { - int k=q[i].to; - if(!dfn[k]) - { - tarjan(k); - low[u]=min(low[u],low[k]); - } - else if(vis[k]) - { - low[u]=min(low[u],dfn[k]); - } - } - if(dfn[u]==low[u]) - { - cnt++; - int temp; - while(1) - { - temp=stap[p]; - vis[temp]=0; - in[temp]=cnt; - --p; - if(temp==u) - break; - } - } -} -void soga() -{ - if(cnt==1) - { - printf("0\n"); - return; - } - int pr,pc; - memset(kr,0,sizeof(kr)); - memset(kc,0,sizeof(kc)); - for(int i=1;i<=n;i++) - { - for(int k=head[i];k!=-1;k=q[k].next) - { - int v=q[k].to; - if(in[v]!=in[i]) - { - kr[in[v]]++; - kc[in[i]]++; - } - } - } - pc=pr=0; - for(int i=1;i<=cnt;i++) - { - if(!kr[i]) - { - pr++; - } - if(!kc[i]) - { - pc++; - } - } - printf("%d\n",max(pr,pc)); -} - - -void add(int a,int b) -{ - q[tol].to=b; - q[tol].next=head[a]; - head[a]=tol++; -} - -int main() -{ - int m; - int T; - scanf("%d",&T); - while(T--) - { - int a,b; - scanf("%d%d",&n,&m); - tol=0; - memset(head,-1,sizeof(head)); - for(int i=0;i -#define ll long long -#define N 100000*2+5 -using namespace std; - -int in[N]; -int head[N],tot; - -struct nodes -{ - int to,next; -} Edge[N]; -void add(int u,int v) -{ - Edge[tot].to = v; - Edge[tot].next = head[u]; - head[u] = tot++; -} -void init() -{ - memset(head,-1,sizeof(head)); - tot = 0; -} -maphashs; - -void solve() -{ - queuetmp; - hashs.clear(); - int n,m,l = 0; - init(); - memset(in,0,sizeof(in)); - - scanf("%d %d",&n,&m); - for(int i = 0; i < m; i++) - { - ll u,v; - scanf("%lld %lld",&u,&v); - if(hashs[u] == 0) - { - hashs[u] = ++l; - - } - u = hashs[u]; - - if(hashs[v] == 0) - { - hashs[v] = ++l; - } - v = hashs[v]; - - add(u,v); - in[v]++; - } - for(int i = 1; i <= l; i++) - { - if(in[i] == 0) - tmp.push(i); - } - - while(!tmp.empty()) - { - int cur = tmp.front(); - - tmp.pop(); - for(int i = head[cur]; i != -1; i = Edge[i].next) - { - int to = Edge[i].to; - in[to]--; - if(in[to] == 0) - tmp.push(to); - } - } - bool ans = true; - for(int i = 1; i <= l; i++) - { - if(in[i] != 0) - { - ans = false; - break; - } - } - if(ans) - printf("No\n"); - else - printf("Yes\n"); -} - -int main(void) -{ - int t,cnt = 0; - scanf("%d",&t); - while(t--) - { - //printf("Case #%d:\n",++cnt); - solve(); - } -} diff --git a/ZZULi0.0/test.py b/ZZULi0.0/test.py deleted file mode 100644 index f510eb21..00000000 --- a/ZZULi0.0/test.py +++ /dev/null @@ -1 +0,0 @@ -what diff --git a/Zsss/2016-05-07-cf660c b/Zsss/2016-05-07-cf660c deleted file mode 100644 index 28257ea2..00000000 --- a/Zsss/2016-05-07-cf660c +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const int MOD = 1E9+7; -const LL N = 3e5+15; -const int maxn = 5e5+15; -const int letter = 130; -const int INF = 1e17; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,k,a[N]; -int main(){ - scanf("%d%d",&n,&k); - for(int i=1;i<=n;i++) scanf("%d",a+i); - int max1=0,maxid=0; - int l=1,r=0,cnt=0; - while(l<=n&&r<=n){ - r++; - while(r<=n&&cnt<=k){ - if(a[r]==0&&cnt==k) {break;} - if(a[r]==0) cnt++; - r++; - } - r--; - if(r-l+1>max1)max1=r-l+1,maxid=l; - if(a[l]==0) cnt--; - l++; - } - printf("%d\n",max1); - if(max1==0) { - for(int i=1;i<=n;i++) printf("0 "); - printf("\n"); - return 0; - } - for(int i=1;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 2e3+15; -const int maxn = 5e5+15; -const int letter = 130; -const int INF = 1e17; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,m; -LL mpow(LL a,LL k){ - LL ans=1; - while(k){ - if(k&1) ans=ans*a%MOD; - a=a*a%MOD; - k=k/2; - } - return ans; -} -int main(){ - scanf("%d%d",&n,&m); - LL sum=mpow(1ll*m,1ll*n); - for(int i=1;i<=n;i++){ - sum=(sum+mpow(1ll*m,n-i+1)*mpow(2ll*m-1,i-1)%MOD)%MOD; - } - printf("%I64d\n",sum); - return 0; -} diff --git a/Zsss/2016-05-08-cf296b b/Zsss/2016-05-08-cf296b deleted file mode 100644 index 187a2d58..00000000 --- a/Zsss/2016-05-08-cf296b +++ /dev/null @@ -1,124 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 1e5+15; -const int maxn = 5e5+15; -const int letter = 130; -const int INF = 1e17; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n; -char s[N],w[N]; -LL mpow(LL a,LL k){ - LL ans=1; - while(k){ - if(k&1) ans=ans*a%MOD; - a=a*a%MOD; - k=k/2; - } - return ans; -} -int main(){ - scanf("%d%s%s",&n,s,w); - int flag1=0,flag2=0; - LL num=0; - for(int i=0;iw[i]) flag1=1; - if(s[i] -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 2e5+15; -const int maxn = 5e5+15; -const int letter = 130; -const int INF = 1e17; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,m,a[15]; -LL gcd(LL a,LL b){ - if(b==0) return a; - return gcd(b,a%b); -} -LL lcm(LL a,LL b){ - return a*b/gcd(a,b); -} -int main(){ - while(scanf("%d%d",&n,&m)!=EOF){ - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 3e4+5000; -const int maxn = 5e5+15; -const int letter = 130; -const int INF = 1e17; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -LL a,b; -int x; -int vis[N],cnt=0; -int prime[10000],ps[32]; -void init(){ - vis[1]=1; - for(int i=2;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 1e5+15; -const int maxn = 5e5+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,m,b[N],vis[N]; -int gcd(int a,int b){ - if(b==0) return a; - return gcd(b,a%b); -} -int main(){ - int T,cas=0; - scanf("%d",&T); - while(T--){ - clr(b,0),clr(vis,0); - int x,cnt=0; - scanf("%d%d",&n,&m); - for(int i=1;i*i<=m;i++){ - if(m%i==0){ - b[cnt++]=i; - if(i!=1&&i*i!=m) b[cnt++]=m/i; - } - } - sort(b,b+cnt); - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 1e3+15; -const int maxn = 5e5+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int x,k; -int vis[N],prime[N],cnt=0; -int ps[30],num; -void init(){ - vis[1]=1; - for(int i=2;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1E9+7; -const LL N = 5e5+15; -const int maxn = 5e5+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,q,a[maxn],ps[maxn]; -int dis[N],vis[N],prime[50000],cnt=0; -vectorG[maxn]; -inline void init(){ - vis[1]=1; - for(int i=2;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1000000007; -const LL N = 3e5+15; -const int maxn = 1e6+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,a[N],ps[N],cnt=0,w[N]; -vectorpp; -struct node{ - int l,r; - bool operator <(const node &p)const{ - return rmax1){ - vs++; - pp.pb(i); - max1=e[i].r; - } - } - if(!vs) puts("-1"); - else { - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1000000007; -const LL N = 4e5+15; -const int maxn = 1e6+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int dfn[N],n,m,w[N],val[N]; -int head[N],tot=0,cnt; -int l[N],r[N]; -LL ans[N<<2],laz[N<<2]; -struct edges{ - int to,next; -}e[N<<1]; -inline void addedges(int u,int v){ - e[tot].to=v,e[tot].next=head[u],head[u]=tot++; -} -inline void dfs(int x,int fa){ - dfn[++cnt]=x; - l[x]=cnt; - for(int i=head[x];i!=-1;i=e[i].next){ - if(e[i].to==fa) continue; - dfs(e[i].to,x); - } - r[x]=cnt; -} -void pushup(int lr){ - ans[lr]=ans[lr<<1]|ans[lr<<1|1]; -} -void pushdown(int lr){ - if(laz[lr]){ - ans[lr<<1]=ans[lr<<1|1]=laz[lr]; - laz[lr<<1]=laz[lr<<1|1]=laz[lr]; - laz[lr]=0; - } -} -void build(int lr,int l,int r){ - if(l>r) return; - laz[lr]=0; - if(l==r){ - ans[lr]=(1LL<>1; - build(lson); - build(rson); - pushup(lr); -} -void update(int ll,int rr,int v,int lr,int l,int r){ - if(ll<=l&&r<=rr){ - ans[lr]=(1LL<>1; - if(ll<=mid) update(ll,rr,v,lson); - if(rr>mid) update(ll,rr,v,rson); - pushup(lr); -} -LL query(int ll,int rr,int lr,int l,int r){ - if(ll<=l&&r<=rr) return ans[lr]; - pushdown(lr); - int mid=(l+r)>>1; - LL ans1=0; - if(ll<=mid) ans1|=query(ll,rr,lson); - if(rr>mid) ans1|=query(ll,rr,rson); - pushup(lr); - return ans1; -} -int main(){ - int id,x,y; - clr(head,-1),tot=0; - n=read(),m=read(); - for(int i=1;i<=n;i++) scanf("%d",w+i); - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1000000007; -const LL N = 1e5+15; -const int maxn = 1e6+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int ax,ay,bx,by,tx,ty,n; -int x[N],y[N]; -int vis[N]; -long double ok(int x1,int y1,int x2,int y2){ - return sqrt(1.0*(x1-x2)*(x1-x2)+1.0*(y1-y2)*(y1-y2)); -} -struct node{ - long double val; - int id; - bool operator <(const node &p)const{ - return val -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1000000007; -const LL N = 5e5+15; -const int maxn = 1e6+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n,k,a[N]; -LL check1(int v){ - LL ans=0; - for(int i=0;iv) ans+=1ll*(a[i]-v); - } - return ans; -} -int main(){ - scanf("%d%d",&n,&k); - LL sum=0; - for(int i=0;i>1; - LL vs=check1(mid); - if(vs<=k)l=mid; - else r=mid; - } - lf=l; - l=1,r=(int)1e9; - while(l+1>1; - LL vs=check2(mid); - if(vs<=k)r=mid; - else l=mid; - } - rf=r; - if(rf-lf>0) printf("%d\n",rf-lf); - else printf("%d\n",sum%n?1:0); - return 0; -} diff --git a/Zsss/2016-05-13-poj2991.cpp b/Zsss/2016-05-13-poj2991.cpp deleted file mode 100644 index be3816a0..00000000 --- a/Zsss/2016-05-13-poj2991.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const LL MOD = 1000000007; -const LL N = 16000+15; -const int maxn = 8e3+15; -const int letter = 130; -const LL INF = 1e18; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int n; -bool vis[maxn][maxn]; -int ans[N<<2]; -struct node{ - int x,yl,yr; - bool operator < (const node &p)const{ - return x>1; - if(ll<=mid) update(ll,rr,v,lson); - if(rr>mid) update(ll,rr,v,rson); - pushup(lr); -} -inline void query(int ll,int rr,int v,int lr,int l,int r){ - if(ans[lr]){ - vis[ans[lr]][v]=1; - return; - } - if(l==r) return; - /// pushdown(lr); - int mid=(l+r)>>1; - if(ll<=mid) query(ll,rr,v,lson); - if(rr>mid) query(ll,rr,v,rson); -} -int main(){ - int T; - scanf("%d",&T); - while(T--){ - clr(vis,0); - scanf("%d",&n); - for(int i=1;i<=n;i++){ - scanf("%d%d%d",&a[i].yl,&a[i].yr,&a[i].x); - } - sort(a+1,a+n+1); - clr(ans,0); - for(int i=1;i<=n;i++){ - query(a[i].yl*2,a[i].yr*2,i,1,0,N); - update(a[i].yl*2,a[i].yr*2,i,1,0,N); - } - LL sum=0; - for(int i=1;i<=n;i++){ - for(int j=i+1;j<=n;j++){ - if(vis[i][j]){ - for(int k=j+1;k<=n;k++){ - if(vis[i][k]&&vis[j][k]) sum++; - } - } - } - } - printf("%I64d\n",sum); - } - return 0; -} diff --git a/Zsss/test.cpp b/Zsss/test.cpp deleted file mode 100644 index 5925f124..00000000 --- a/Zsss/test.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define PI 2*asin(1.0) -#define LL long long -#define pb push_back -#define pa pair -#define clr(a,b) memset(a,b,sizeof(a)) -#define lson lr<<1,l,mid -#define rson lr<<1|1,mid+1,r -#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) -#define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin -const int MOD = 1E9+7; -const LL N = 2e5+15; -const int maxn = 5e5+15; -const int letter = 130; -const int INF = 1e17; -const double pi=acos(-1.0); -const double eps=1e-10; -using namespace std; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} - while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} - return x*f; -} -int main(){ - return 0; -} diff --git a/axp/cf577A b/axp/cf577A deleted file mode 100644 index c87bdc28..00000000 --- a/axp/cf577A +++ /dev/null @@ -1,35 +0,0 @@ -/* *********************************************** -Author :axp -Created Time :2016/5/10 22:27:23 -TASK :A.cpp -LANG :C++ -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int n,x; -int ans; - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - cin>>n>>x; - for(int i=1;i<=n;i++) - if(x%i==0 && x/i<=n) - ans++; - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const int N = 1e6+10; -int n,m; -bool dp[2][N]; - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - scanf("%d%d",&n,&m); - - for(int i=1;i<=n;i++) - { - bool k=i&1; - int x; - scanf("%d",&x); - for(int j=0;j -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int n; -vector ve; - -bool isp(int x) -{ - for(int i=2;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int n; -string s; - -string f(int x) -{ - int t=0; - int m=0; - while(x) - { - t*=10; - t+=x%10; - x/=10; - m++; - } - string re; - while(m--) - { - re+=t%10+'0'; - t/=10; - } - return re; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - cin>>n; - for(int i=1;i<=n;i++) - s+=f(i); - //cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int T; -int a,b,c,k; -int ans; - -int main() -{ - freopen("C-large.in","r",stdin); - freopen("out.txt","w",stdout); - scanf("%d",&T); - for(int kase=1;kase<=T;kase++) - { - scanf("%d%d%d%d",&a,&b,&c,&k); - ans=a*b*min(c,k); - printf("Case #%d: %d\n",kase,ans); - int now; - int be=1; - for(int i=1;i<=a;i++) - { - now=be++; - for(int j=1;j<=b;j++) - for(int m=1;m<=min(c,k);m++) - { - printf("%d %d %d\n",i,j,now); - now++; - if(now>c)now-=c; - } - } - } - return 0; -} diff --git a/comma_01/comma_01_subject1.7z b/comma_01/comma_01_subject1.7z deleted file mode 100644 index d941c56d..00000000 Binary files a/comma_01/comma_01_subject1.7z and /dev/null differ diff --git a/comma_01/readme.txt b/comma_01/readme.txt deleted file mode 100644 index b8f70348..00000000 --- a/comma_01/readme.txt +++ /dev/null @@ -1 +0,0 @@ -This is comma_01's world! diff --git a/flag/2016_05_05.cpp b/flag/2016_05_05.cpp deleted file mode 100644 index 77505008..00000000 --- a/flag/2016_05_05.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define mkp make_pair -#define R first -#define L second.first -#define id second.second -#define val first -#define p second -using namespace std; -const int maxn = 1e4 + 5; -const int maxm = 1e5 + 5; -vector < pair < int, pair < int, int > > > q; -vector < pair < int, int > > x[2]; -set < int > vis; -map < int, int > pre; -int a[maxn], ans[maxm]; - -int gcd(int a, int b){ - return !b ? a : gcd(b, a % b); -} - -struct BIT{ - int sum[maxn], n; - - void init(int n){ - this->n = n; - memset(sum, 0, sizeof sum); - } - - inline int lowbit(int x){ - return x & (-x); - } - - void update(int x, int val){ - for(int i = x; i <= n; i += lowbit(i)){ - sum[i] += val; - } - } - - int query(int l, int r){ - int res = 0; - for(int i = r; i; i -= lowbit(i)){ - res += sum[i]; - } - for(int i = l - 1; i; i -= lowbit(i)){ - res -= sum[i]; - } - return res; - } -}gao; - -int main(){ - int T, n, m, l, r; - scanf("%d", &T); - while(T--){ - scanf("%d%d", &n, &m); - q.clear(); - x[0].clear(); - x[1].clear(); - pre.clear(); - vis.clear(); - gao.init(n); - for(int i = 1; i <= n; i++){ - scanf("%d", &a[i]); - } - for(int i = 1; i <= m; i++){ - scanf("%d%d", &l, &r); - q.push_back(mkp(r, mkp(l, i))); - } - sort(q.begin(), q.end()); - int i = 1, t1 = 0, t2 = 1; - for(int t = 0; t < q.size(); t++){ - for(; i <= n && i <= q[t].R; i++){ - t1 ^= 1, t2 ^= 1; - x[t2].clear(); - vis.clear(); - vis.insert(a[i]); - for(int j = x[t1].size() - 1; j >= 0; j--){ - int tmp = gcd(x[t1][j].val, a[i]); - if(vis.find(tmp) == vis.end()){ - x[t2].push_back(mkp(tmp, x[t1][j].p)); - vis.insert(tmp); - } - } - x[t2].push_back(mkp(a[i], i)); - for(int j = 0; j < x[t2].size(); j++){ - if(!pre.count(x[t2][j].val)){ - gao.update(x[t2][j].p, 1); - pre[x[t2][j].val] = x[t2][j].p; - }else if(pre[x[t2][j].val] < x[t2][j].p){ - gao.update(pre[x[t2][j].val], -1); - gao.update(x[t2][j].p, 1); - pre[x[t2][j].val] = x[t2][j].p; - } - } - } - ans[q[t].id] = gao.query(q[t].L, q[t].R); - } - for(int i = 1; i <= m; i++){ - printf("%d\n", ans[i]); - } - } - return 0; -} diff --git a/flag/2016_05_06.cpp b/flag/2016_05_06.cpp deleted file mode 100644 index c0b25160..00000000 --- a/flag/2016_05_06.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#pragma comment(linker,"/STACK:102400000,102400000") -#include -#include -#include -using namespace std; -typedef long long LL; -const int maxn = 1e5 + 5; -const int maxh = 1e6 + 5; -const int md = 1e6 + 3; -struct Edge{ - int v, next; -}E[maxn << 1]; -int head[maxn], tol, n, k; -int vis[maxn], sz[maxn], mx[maxn], minSize, root; -LL mul1[maxn], mul2[maxn]; -int ID[maxn], cnt; -LL val1[maxn], val2[maxn]; -int hah[maxh], id[maxh], judge; - -void add(int x, int y){ - if(hah[x] != judge){ - hah[x] = judge; - id[x] = y; - }else if(id[x] > y){ - id[x] = y; - } -} - -LL Inv(LL a){ - int k = md - 2; - LL ans = 1; - while(k){ - if(k & 1) ans = ans * a % md; - a = a * a % md; - k >>= 1; - } - return ans; -} - -void init(){ - memset(head, -1, sizeof head); - tol = 0; - memset(hah, -1, sizeof hah); - judge = 0; -} - -void add_edge(int u, int v){ - E[tol].v = v; - E[tol].next = head[u]; - head[u] = tol++; -} - -void get_size(int u, int pre){ - sz[u] = 1; - mx[u] = 0; - for(int i = head[u]; ~i; i = E[i].next){ - int v = E[i].v; - if(v == pre || vis[v]) continue; - get_size(v, u); - sz[u] += sz[v]; - if(sz[v] > mx[u]) mx[u] = sz[v]; - } -} - -void get_root(int rt, int u, int pre){ - if(sz[rt] - sz[u] > mx[u]){ - mx[u] = sz[rt] - sz[u]; - } - if(mx[u] < minSize){ - minSize = mx[u]; - root = u; - } - for(int i = head[u]; ~i; i = E[i].next){ - int v = E[i].v; - if(v == pre || vis[v]) continue; - get_root(rt, v, u); - } -} - -void get_mul(int u, int pre, LL x, LL y){ - mul1[cnt] = x; - mul2[cnt] = y; - ID[cnt++] = u; - for(int i = head[u]; ~i; i = E[i].next){ - int v = E[i].v; - if(v == pre || vis[v]) continue; - get_mul(v, u, x * val1[v] % md, y * val2[v] % md); - } -} - -int flag, s, e; - -void update(int u, int v){ - if(u > v) swap(u, v); - if(!flag || u < s || u == s && v < e){ - flag = 1; - s = u; - e = v; - } -} - -void dfs(int u){ - minSize = n + 1; - get_size(u, -1); - get_root(u, u, -1); - vis[root] = 1; - add(val1[root], root); - for(int i = head[root]; ~i; i = E[i].next){ - int v = E[i].v; - if(vis[v]) continue; - cnt = 0; - get_mul(v, root, val1[v] % md, val2[v] * k % md); - for(int j = 0; j < cnt; j++){ - if(hah[mul2[j]] == judge){ - update(ID[j], id[mul2[j]]); - } - } - for(int j = 0; j < cnt; j++){ - add(mul1[j] * val1[root] % md, ID[j]); - } - } - ++judge; - for(int i = head[root]; ~i; i = E[i].next){ - if(!vis[E[i].v]) dfs(E[i].v); - } -} - -int main(){ - while(scanf("%d%d", &n, &k) != EOF){ - init(); - for(int i = 1; i <= n; i++){ - scanf("%I64d", &val1[i]); - val2[i] = Inv(val1[i]); - } - for(int i = 1; i < n; i++){ - int u, v; - scanf("%d%d", &u, &v); - add_edge(u, v); - add_edge(v, u); - } - flag = 0; - dfs(1); - if(!flag) puts("No solution"); - else printf("%d %d\n", s, e); - } - return 0; -} diff --git a/flag/2016_05_07.cpp b/flag/2016_05_07.cpp deleted file mode 100644 index 6c024651..00000000 --- a/flag/2016_05_07.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -using namespace std; -typedef long long LL; -const int md = 1e9 + 7; -const int maxn = 305; -const int B = 300; -LL dp[maxn][maxn * 2][3], g[maxn * 2][3]; -int sz[maxn]; -struct Edge{ - int v, next; -}E[maxn << 1]; -int head[maxn], tol; - -void init(){ - memset(head, -1, sizeof head); - tol = 0; -} - -void add_edge(int u, int v){ - E[tol].v = v; - E[tol].next = head[u]; - head[u] = tol++; -} - -void add(LL &a, LL b){ - (a += b) %= md; -} - -void dfs(int u, int pre){ - memset(dp[u], 0, sizeof dp[u]); - dp[u][1 + B][1] = 1; - dp[u][0 + B][0] = 2; - sz[u] = 1; - for(int i = head[u]; ~i; i = E[i].next){ - int v = E[i].v; - if(v == pre) continue; - dfs(v, u); - memset(g, 0, sizeof g); - for(int j = -sz[u] + B; j <= sz[u] + B; j++){ - for(int k = -sz[v] + B; k <= sz[v] + B; k++){ - int x = j + k - B; - if(x > 600 || x < 0) continue; - add(g[x][0], dp[u][j][0] * dp[v][k][0] % md); - add(g[x][0], dp[u][j][0] * dp[v][k][1] % md); - add(g[x][0], dp[u][j][0] * dp[v][k][2] % md); - - add(g[x][1], dp[u][j][1] * dp[v][k][0] % md); - if(x - 3 >= 0) - add(g[x - 3][2], dp[u][j][1] * dp[v][k][1] % md); - add(g[x + 1][1], dp[u][j][1] * dp[v][k][2] % md); - - add(g[x][2], dp[u][j][2] * dp[v][k][0] % md); - add(g[x + 1][1], dp[u][j][2] * dp[v][k][1] % md); - add(g[x + 1][2], dp[u][j][2] * dp[v][k][2] % md); - } - } - memcpy(dp[u], g, sizeof g); - sz[u] += sz[v]; - } -} - -int main(){ - int n, u, v; - while(scanf("%d", &n) != EOF){ - init(); - for(int i = 1; i < n; i++){ - scanf("%d%d", &u, &v); - add_edge(u, v); - add_edge(v, u); - } - dfs(1, -1); - LL ans = 0; - for(int i = -sz[1] + B; i <= sz[1] + B; i++){ - LL sum = 0; - for(int j = 0; j < 3; j++){ - add(sum, dp[1][i][j]); - } - add(ans, sum * max(0, i - B) % md); - } - ans = (ans * 3LL) % md; - printf("%lld\n", ans); - } - return 0; -} diff --git a/flag/2016_05_08.cpp b/flag/2016_05_08.cpp deleted file mode 100644 index 3ae90397..00000000 --- a/flag/2016_05_08.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include -#include -#include -using namespace std; -typedef long long LL; -#define lson rt << 1 -#define rson rt << 1 | 1 -const int maxn = 1e5 + 5; -LL a[maxn]; - -struct SegTree1{ - struct SegTree{ - int l, r; - int sign, flag; - LL x; - void gao(LL y){ - flag = 1; - x = y - x; - sign = -sign; - } - }tree[maxn << 2]; - - void push_down(int rt){ - if(tree[rt].flag){ - tree[lson].gao(tree[rt].x); - tree[rson].gao(tree[rt].x); - tree[rt].flag = 0; - tree[rt].x = 0; - } - } - - void build(int l, int r, int rt){ - tree[rt].l = l; - tree[rt].r = r; - tree[rt].flag = 0; - tree[rt].x = 0; - tree[rt].sign = 1; - if(l == r) return; - int mid = (l + r) >> 1; - build(l, mid, lson); - build(mid + 1, r, rson); - } - - void update(int l, int r, int rt, LL x){ - if(l <= tree[rt].l && tree[rt].r <= r){ - tree[rt].gao(x); - return; - } - push_down(rt); - int mid = (tree[rt].l + tree[rt].r) >> 1; - if(l <= mid) - update(l, r, lson, x); - if(mid < r) - update(l, r, rson, x); - } - - LL query(int p, int rt){ - if(p == tree[rt].l && tree[rt].r == p){ - return tree[rt].x + tree[rt].sign * a[p]; - } - push_down(rt); - int mid = (tree[rt].l + tree[rt].r) >> 1; - if(p <= mid) - return query(p, lson); - else - return query(p, rson); - } - -}gao1; - - -struct SegTree2{ - struct SegTree{ - int l, r; - LL gcd; - }tree[maxn << 2]; - - void push_up(int rt){ - tree[rt].gcd = __gcd(tree[lson].gcd, tree[rson].gcd); - } - - void build(int l, int r, int rt){ - tree[rt].l = l; - tree[rt].r = r; - if(l == r){ - tree[rt].gcd = abs(a[r] - a[r - 1]); - return; - } - int mid = (l + r) >> 1; - build(l, mid, lson); - build(mid + 1, r, rson); - push_up(rt); - } - - void update(int p, int rt, LL val){ - if(p == tree[rt].l && tree[rt].r == p){ - tree[rt].gcd = val; - return; - } - int mid = (tree[rt].l + tree[rt].r) >> 1; - if(p <= mid) - update(p, lson, val); - else - update(p, rson, val); - push_up(rt); - } - - LL query(int l, int r, int rt){ - if(l <= tree[rt].l && tree[rt].r <= r){ - return tree[rt].gcd; - } - int mid = (tree[rt].l + tree[rt].r) >> 1; - LL res = -1; - if(l <= mid) - res = query(l, r, lson); - if(mid < r){ - LL tmp = query(l, r, rson); - if(res == -1) - res = tmp; - else - res = __gcd(res, tmp); - } - return res; - } - -}gao2; - -int main(){ - int n, m, type, l, r, x; - while(scanf("%d%d", &n, &m) != EOF){ - for(int i = 1; i <= n; i++){ - scanf("%lld", &a[i]); - } - gao1.build(1, n, 1); - gao2.build(2, n, 1); - for(int i = 1; i <= m; i++){ - scanf("%d", &type); - if(type == 1){ - scanf("%d%d%d", &l, &r, &x); - gao1.update(l, r, 1, x); - if(l != 1){ - gao2.update(l, 1, abs(gao1.query(l, 1) - gao1.query(l - 1, 1))); - } - if(r != n){ - gao2.update(r + 1, 1, abs(gao1.query(r + 1, 1) - gao1.query(r, 1))); - } - }else{ - scanf("%d%d", &l, &r); - if(l == r) - printf("%lld\n", gao1.query(l, 1)); - else - printf("%lld\n", __gcd(gao1.query(l, 1), gao2.query(l + 1, r, 1))); - } - } - } - return 0; -} diff --git a/flag/2016_05_09.cpp b/flag/2016_05_09.cpp deleted file mode 100644 index 25788de7..00000000 --- a/flag/2016_05_09.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#include -using namespace std; -typedef long long LL; -const int md = 2015; -const int maxn = 1e5 + 5; -int dp[7][maxn][2][7]; - -void add(int &a, int b){ - (a += b) %= md; -} - -void init(){ - for(int x = 1; x < 7; x++){ - dp[x][x + 1][0][1] = 1; - for(int i = x + 2; i < maxn; i++){ - for(int a = 0; a < 2; a++){ - for(int b = 0; b < 7; b++){ - if(b + 1 < 7) - add(dp[x][i][a][b + 1], dp[x][i - 1][a][b]); - add(dp[x][i][!a][1], dp[x][i - 1][a][b]); - } - } - } - } -} - -int main(){ - init(); - int T, n; - scanf("%d", &T); - for(int cas = 1; cas <= T; cas++){ - scanf("%d", &n); - if(n == 1){ - printf("Case #%d: 2\n", cas); - continue; - } - int ans = 0; - for(int x = 0; x < 7; x++){ - for(int a = 0; a < 2; a++){ - for(int b = 1; b < 7; b++){ - if(x + b <= n){ - if(1 == a && x + b >= 7) continue; - add(ans, dp[x][n][a][b] * 2 % md); - } - } - } - } - if(n < 7) ans += 2; - printf("Case #%d: %d\n", cas, ans); - } - return 0; -} diff --git a/flag/2016_05_10.cpp b/flag/2016_05_10.cpp deleted file mode 100644 index 1cbcf8ed..00000000 --- a/flag/2016_05_10.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -using namespace std; -typedef long long LL; -#define mkp make_pair -const int md = 1000000007; -const LL up = 1e14 + 5; -const int maxn = 1e7 + 5; -bool isp[maxn]; -vector < int > p; -vector < pair < LL, int > > mi; -vector < int > ans; - -void init(){ - memset(isp, true, sizeof isp); - mi.push_back(mkp(1, 1)); - for(int i = 2; i < maxn; i++){ - if(isp[i]){ - p.push_back(i); - for(double j = (double)i * i; j < up; j *= i){ - mi.push_back(mkp((LL)j, i)); - } - } - for(int j = 0; j < p.size() && (LL)i * p[j] < maxn; j++){ - isp[i * p[j]] = false; - if(i % p[j] == 0) break; - } - } - sort(mi.begin(), mi.end()); - ans.push_back(1); - for(int i = 1; i < mi.size(); i++){ - ans.push_back((LL)ans[i - 1] * mi[i].second % md); - } -} - -int main(){ - init(); - int T; - scanf("%d", &T); - for(int cas = 1; cas <= T; cas++){ - LL n; - scanf("%lld", &n); - int l = 0, r = mi.size() - 1, mid; - while(l < r){ - mid = (l + r + 1) >> 1; - if(mi[mid].first <= n) - l = mid; - else - r = mid - 1; - } - printf("Case %d: %d\n", cas, ans[r]); - } - return 0; -} diff --git a/flag/2016_05_11.cpp b/flag/2016_05_11.cpp deleted file mode 100644 index a169d32f..00000000 --- a/flag/2016_05_11.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include -using namespace std; -#define lson rt << 1 -#define rson rt << 1 | 1 -typedef long long LL; -const int INF = 0x3f3f3f3f; -const int maxn = 2005; -vector < int > p; -struct SegTree{ - int l, r, flag; - int sum1, sum2, sum3; -}tree[maxn << 2]; - -void push_up(int rt){ - if(tree[rt].flag){ - tree[rt].sum1 = p[tree[rt].r] - p[tree[rt].l]; - }else if(tree[rt].l + 1 == tree[rt].r){ - tree[rt].sum1 = 0; - }else{ - tree[rt].sum1 = tree[lson].sum1 + tree[rson].sum1; - } - if(tree[rt].flag > 1){ - tree[rt].sum2 = p[tree[rt].r] - p[tree[rt].l]; - }else if(tree[rt].l + 1 == tree[rt].r){ - tree[rt].sum2 = 0; - }else if(tree[rt].flag == 1){ - tree[rt].sum2 = tree[lson].sum1 + tree[rson].sum1; - }else{ - tree[rt].sum2 = tree[lson].sum2 + tree[rson].sum2; - } - if(tree[rt].flag > 2){ - tree[rt].sum3 = p[tree[rt].r] - p[tree[rt].l]; - }else if(tree[rt].l + 1 == tree[rt].r){ - tree[rt].sum3 = 0; - }else if(tree[rt].flag == 2){ - tree[rt].sum3 = tree[lson].sum1 + tree[rson].sum1; - }else if(tree[rt].flag == 1){ - tree[rt].sum3 = tree[lson].sum2 + tree[rson].sum2; - }else{ - tree[rt].sum3 = tree[lson].sum3 + tree[rson].sum3; - } -} - -void build(int l, int r, int rt){ - tree[rt].l = l; - tree[rt].r = r; - tree[rt].flag = 0; - tree[rt].sum1 = tree[rt].sum2 = tree[rt].sum3 = 0; - if(l + 1 == r) return; - int mid = (l + r) >> 1; - build(l, mid, lson); - build(mid, r, rson); -} - -void update(int l, int r, int rt, int val){ - if(l <= tree[rt].l && tree[rt].r <= r){ - tree[rt].flag += val; - push_up(rt); - return ; - } - int mid = (tree[rt].l + tree[rt].r) >> 1; - if(l < mid) - update(l, r, lson, val); - if(mid < r) - update(l, r, rson, val); - push_up(rt); -} - -struct Seg{ - int l, r, h, d; - Seg(){ } - Seg(int _l, int _r, int _h, int _d): l(_l), r(_r), h(_h), d(_d) { } - bool operator<(const Seg& tmp) const{ - return h < tmp.h; - } -}seg[maxn]; - -struct Cube{ - int x1, y1, z1, x2, y2, z2; - void read(){ - scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2); - } -}cube[maxn]; -vector < int > Z; - -LL Area(int z1, int z2, int n){ - p.clear(); - int tol = 0; - for(int i = 1; i <= n; i++){ - if(cube[i].z1 <= z1 && z2 <= cube[i].z2){ - seg[tol++] = Seg(cube[i].x1, cube[i].x2, cube[i].y1, 1); - seg[tol++] = Seg(cube[i].x1, cube[i].x2, cube[i].y2, -1); - p.push_back(cube[i].x1); - p.push_back(cube[i].x2); - } - } - p.push_back(-INF); - sort(p.begin(), p.end()); - p.erase(unique(p.begin(), p.end()), p.end()); - sort(seg, seg + tol); - build(1, (int)(p.size() - 1), 1); - LL ans = 0; - for(int i = 0; i < tol; i++){ - int l = lower_bound(p.begin(), p.end(), seg[i].l) - p.begin(); - int r = lower_bound(p.begin(), p.end(), seg[i].r) - p.begin(); - update(l, r, 1, seg[i].d); - ans += (LL)tree[1].sum3 * (seg[i + 1].h - seg[i].h); - } - return ans; -} - -int main(){ - int T, n; - scanf("%d", &T); - for(int cas = 1; cas <= T; cas++){ - scanf("%d", &n); - Z.clear(); - for(int i = 1; i <= n; i++){ - cube[i].read(); - Z.push_back(cube[i].z1); - Z.push_back(cube[i].z2); - } - sort(Z.begin(), Z.end()); - Z.erase(unique(Z.begin(), Z.end()), Z.end()); - LL ans = 0; - for(int i = 1; i < Z.size(); i++){ - ans += Area(Z[i - 1], Z[i], n) * (Z[i] - Z[i - 1]); - } - printf("Case %d: %lld\n", cas, ans); - } - return 0; -} diff --git a/flag/2016_05_12.cpp b/flag/2016_05_12.cpp deleted file mode 100644 index c238328d..00000000 --- a/flag/2016_05_12.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; -typedef long long LL; -const int maxn = 200005; -#define lowbit(x) (x&(-x)) -struct BIT{ - int sum[maxn], n; - - void init(int n){ - this->n = n; - memset(sum, 0, sizeof sum); - } - - void update(int x, int val){ - for(int i = x; i <= n; i += lowbit(i)){ - sum[i] += val; - } - } - - int query(int l, int r){ - int s = 0; - for(int i = r; i; i -= lowbit(i)){ - s += sum[i]; - } - for(int i = l - 1; i; i -= lowbit(i)){ - s -= sum[i]; - } - return s; - } - -}gao1, gao2; -struct Point{ - int x, y; - void read(){ - scanf("%d%d", &x, &y); - } -}p[maxn]; -vector < int > X; -vector < int > Y; -vector < int > px[maxn]; -vector < int > ans[maxn]; - -int main(){ - int n; - while(scanf("%d", &n) != EOF){ - if(!n) break; - for(int i = 0; i < maxn; i++){ - px[i].clear(); - ans[i].clear(); - } - X.clear(); - Y.clear(); - for(int i = 1; i <= n; i++){ - p[i].read(); - X.push_back(p[i].x); - Y.push_back(p[i].y); - } - sort(X.begin(), X.end()); - sort(Y.begin(), Y.end()); - X.erase(unique(X.begin(), X.end()), X.end()); - Y.erase(unique(Y.begin(), Y.end()), Y.end()); - gao1.init(Y.size()); - gao2.init(Y.size()); - for(int i = 1; i <= n; i++){ - p[i].x = lower_bound(X.begin(), X.end(), p[i].x) - X.begin() + 1; - p[i].y = lower_bound(Y.begin(), Y.end(), p[i].y) - Y.begin() + 1; - px[p[i].x].push_back(p[i].y); - gao2.update(p[i].y, 1); - } - int Stan = 0, Ollie = 0, res1, res2, tmp; - for(int i = 1; i <= X.size(); i++){ - for(int j = 0; j < px[i].size(); j++){ - gao2.update(px[i][j], -1); - } - res1 = res2 = -1; - for(int j = 0; j < px[i].size(); j++){ - tmp = gao1.query(px[i][j] + 1, Y.size()) + gao2.query(1, px[i][j] - 1); - if(tmp > res2){ - res2 = tmp; - res1 = gao1.query(1, px[i][j] - 1) + gao2.query(px[i][j] + 1, Y.size()); - } - } - ans[res1].push_back(res2); - for(int j = 0; j < px[i].size(); j++){ - gao1.update(px[i][j], 1); - } - } - for(int i = maxn - 1; i >= 0; i--){ - if(ans[i].size()){ - sort(ans[i].begin(), ans[i].end()); - ans[i].erase(unique(ans[i].begin(), ans[i].end()), ans[i].end()); - printf("Stan: %d; Ollie:", i); - for(int j = 0; j < ans[i].size(); j++){ - printf(" %d", ans[i][j]); - } - puts(";"); - break; - } - } - } - return 0; -} diff --git a/flag/2016_05_13.cpp b/flag/2016_05_13.cpp deleted file mode 100644 index b4b887e2..00000000 --- a/flag/2016_05_13.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include -using namespace std; -const int INF = 0x3f3f3f3f; -const int maxn = 1e5 + 5; -int deg[maxn]; - -int main(){ - int n, x, T; - scanf("%d", &T); - while(T--){ - scanf("%d", &n); - memset(deg, 0, sizeof deg); - for(int i = 2; i <= n; i++){ - scanf("%d", &x); - x++; - deg[x]++; - deg[i]++; - } - int f = 1, cnt = 0, ans1, ans2 = 0; - for(int i = 1; i <= n; i++){ - if(deg[i] == 1) cnt++; - if(f) ans2 += (deg[i] + 1) / 2, f = 0; - else ans2 += (deg[i] - 1) / 2; - } - ans1 = (cnt + 1) / 2; - printf("%d %d\n", ans1, ans2); - } - return 0; -} diff --git "a/flag/\345\215\232\345\256\242\345\234\260\345\235\200.txt" "b/flag/\345\215\232\345\256\242\345\234\260\345\235\200.txt" deleted file mode 100644 index 28de1ec1..00000000 --- "a/flag/\345\215\232\345\256\242\345\234\260\345\235\200.txt" +++ /dev/null @@ -1 +0,0 @@ -http://www.linmeichen.com/ diff --git a/haihongS/2016_05_06.cpp b/haihongS/2016_05_06.cpp deleted file mode 100644 index ba1c9d94..00000000 --- a/haihongS/2016_05_06.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* *********************************************** -Author :shootPlane -Created Time :2016年05月06日 星期五 15时01分21秒 -File Name :3368.cpp -Blog :http://haihongblog.com -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn=1e5+9; -const int inf=1e9+9; - -struct lisan -{ - int v,l,r; -}vv[maxn]; - -struct II -{ - int maxx,l,r; -}tree[4*maxn]; - -int n,q; -int num[maxn]; - -int build(int node,int l,int r); -int query(int node,int l,int r,int L,int R); - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - while(scanf("%d",&n) && n) - { - scanf("%d",&q); - - int loca=0; - scanf("%d",&num[0]); - vv[loca].v=num[0],vv[loca].l=0; - int last=num[0]; - - for(int i=1;itree[node].r) return 0; - if(l==r) - { - return min(tree[node].r,R)-max(tree[node].l,L)+1; - } - if(L<=tree[node].l && tree[node].r<=R) return tree[node].maxx; - - int mid=l+(r-l)/2; - int t1=query(2*node+1,l,mid,L,R); - int t2=query(2*node+2,mid+1,r,L,R); - return max(t1,t2); -} - -// [l,r] -int build(int node,int l,int r) -{ - if(l==r) - { - tree[node].l=vv[l].l,tree[node].r=vv[l].r; - tree[node].maxx=tree[node].r-tree[node].l+1; - return 0; - } - int mid=l+(r-l)/2; - build(2*node+1,l,mid); - build(2*node+2,mid+1,r); - tree[node].l=tree[2*node+1].l; - tree[node].r=tree[2*node+2].r; - tree[node].maxx=max(tree[2*node+1].maxx,tree[2*node+2].maxx); - return 0; -} diff --git a/haihongS/2016_05_07.cpp b/haihongS/2016_05_07.cpp deleted file mode 100644 index 4192c970..00000000 --- a/haihongS/2016_05_07.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* *********************************************** -Author :shootPlane -Created Time :2016年05月07日 星期六 14时02分20秒 -File Name :1201.cpp -Blog :http://haihongblog.com -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn=1e5+9; -const int inf=1e9+9; - -struct II -{ - int a,b,c; -}num[maxn]; - -int sum[maxn]; - -int lowbit(int x); -int getsum(int x); -int update(int x,int v); - -int cmp(const II &x,const II &y); - - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - int n; - while(~scanf("%d",&n)) - { - for(int i=0;i0;j--) - { - int t1=getsum(j)-getsum(j-1); - if(t1==1) - continue; - tmp--; - update(j,1); - ans++; - } - } - printf("%d\n",ans); - } - return 0; -} - -int update(int x,int v) -{ - while(x0) - { - tmp+=sum[x]; - x-=lowbit(x); - } - return tmp; -} - -int lowbit(int x) -{ - return x&(-x); -} - -int cmp(const II &x,const II &y) -{ - if(x.b==y.b) return x.a -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn=21; -const int inf=1e9+9; - -vector aha[maxn]; -int dp[2][1< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn=2e6+9; -const int inf=1e9+9; - -struct II -{ - ll n,m; -} num[maxn]; - - -int cmp(const II &x,const II &y); - -int main() -{ - ll x; - while(cin>>x) - { - if(x==1) - { - printf("1\n1 1\n"); - continue; - } - int loca=0; - ll len=x; - for(ll i=1; i<=maxn*10; i++) - { - - if(i>=len) break; - ll tmp=i*(i+1); - if((6*x)%tmp==0) - { - tmp=6*x/tmp; - tmp=(tmp+i-1); - if(tmp%3!=0) continue; - tmp/=3; - if(tmp -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn=13000; -const int mod=1e8; - -int n,m; -int num[20]; -ll dp[20][maxn]; - -int main() -{ - while(~scanf("%d%d",&n,&m)) - { - for(int i=1;i<=n;i++) - { - int tmp=0; - for(int j=0;j -#include -#include -#include -#include -#include - -using namespace std; -typedef long long ll; -const int maxn=2e5+9; -const int inf=1e9+9; -struct II -{ - int x,y,area,p; -}num[500],rec[500]; - -int n; -int dp[maxn]; - -int main() -{ - while(scanf("%d",&n) && n) - { - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn=1e5+9; -const int inf=1e9+9; - -struct II -{ - int h,a; -}num[maxn]; - -int main() -{ - int n; - while(~scanf("%d",&n)) - { - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int maxn = 1e5 + 9; -const int inf = 1e9 + 9; - -string num[20]; -int n; -int dp[1 << 17][20], cost[20][20]; -int use[20]; -string ans; - -int cmp(const string &x, const string &y); -int init(); -int dfs(int cnt, int state, string s, int loca, int len); - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - int t; - scanf("%d", &t); - int cass = 1; - while (t--) - { - scanf("%d", &n); - //for (int i = 0; i> num[i]; - int len = 0; - for (int i = 0; i < n; i++) - { - cin >> num[len]; - for (int j = 0; j < len;j++) - { - if(num[j].find(num[len])> u) & 1) continue; - if (dp[i][j] == inf) continue; - int tmp = num[u].length(); - //dp[i | (1 << u)][j] = min(dp[i | (1 << u)][j], dp[i][j] + tmp + cost[j][u]); - dp[i | (1 << u)][u] = min(dp[i | (1 << u)][u], dp[i][j] + tmp + cost[u][j]); - } - } - } - int loca = 0, minn = dp[(1 << len) - 1][0]; - for (int i = 1; ij - int up = min(num[i].length(), num[j].length()); - int len = num[i].length(); - int tmp = 0; - for (int k = 0; k<=up; k++) - { - int ff = 1; - for (int s = 0; s -#include -#include -#include -#include -#include -#include - -using namespace std; -typedef long long ll; -const int maxn=2e5+9; - -struct II -{ - vector aha; - int lchild,rchild; -}tree[4*maxn]; - -int n,m; -int num[maxn],bb[maxn]; - -int build(int node,int l,int r); -int query(int node,int l,int r,int L,int R,int x); - -int main() -{ - while(~scanf("%d%d",&n,&m)) - { - for(int i=0;i=k) - { - up=mid-1; - ans=min(ans,mid); - } - else - low=mid+1; - } - printf("%d\n",bb[ans]); - } - } - return 0; -} - -// [l,r) -int query(int node,int l,int r,int L,int R,int x) -{ - if(R<=l || L>=r) return 0; - if(L<=l && r<=R) - { - int tmp=upper_bound(tree[node].aha.begin(),tree[node].aha.end(),x)-tree[node].aha.begin(); - return tmp; - } - int mid=l+(r-l)/2; - int t1=query(2*node+1,l,mid,L,R,x); - int t2=query(2*node+2,mid,r,L,R,x); - return t1+t2; -} - -// [l,r) -int build(int node,int l,int r) -{ - if(l+1==r) - { - //tree[node].aha.clear(); - tree[node].aha.push_back(num[l]); - return node; - } - int mid=l+(r-l)/2; - tree[node].lchild=build(2*node+1,l,mid); - tree[node].rchild=build(2*node+2,mid,r); - int u=tree[node].lchild,v=tree[node].rchild; - - //tree[node].aha.clear(); - tree[node].aha.resize(r-l); - merge(tree[u].aha.begin(),tree[u].aha.end(),tree[v].aha.begin(),tree[v].aha.end(),tree[node].aha.begin()); - return node; -} diff --git a/hetanglianyi/bzoj1566.cpp b/hetanglianyi/bzoj1566.cpp deleted file mode 100644 index 058fb453..00000000 --- a/hetanglianyi/bzoj1566.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -using namespace std; -int f[20][1000][1000]; -int n, m; -char a[1000], b[1000]; -const int mod = 1024523; -int main() -{ - scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) - scanf(" %c", &a[i]); - for (int i = 1; i <= m; i++) - scanf(" %c", &b[i]); - - memset(f, 0, sizeof(f)); - f[0][0][0] = 1; - for (int i = 1; i <= n+m; i++) - { - int t = min(i, n); - for (int j = 0; j <= t; j++) - for (int k = 0; k <= t; k++) - { - if (j > 0 && k > 0 && a[j] == a[k]) f[i%2][j][k] += f[(i-1)%2][j-1][k-1]; - if (b[i-j] == b[i-k]) f[i%2][j][k] += f[(i-1)%2][j][k]; - if (j > 0 && a[j] == b[i-k]) f[i%2][j][k] += f[(i-1)%2][j-1][k]; - if (k > 0 && b[i-j] == a[k]) f[i%2][j][k] += f[(i-1)%2][j][k-1]; - f[i%2][j][k] %= mod; - // cout << i<<' '< -#include -#include -#include -#include -using namespace std; -template -class Point //学习自王哥高二的代码…… -{ - private: - _Tp _x, _y; - public: - Point() {_x = _y = 0; } - Point(_Tp x, _Tp y) - { - _x = x; - _y = y; - } - _Tp x(); - _Tp y(); - Point &operator=(Point p) - { - _x = p.x(); - _y = p.y(); - return *this; - } - Point operator+(Point b) const - { - Point c(_x + b.x(), _y + b.y()); - return c; - } - Point operator-(Point b) const - { - Point c(_x - b.x(), _y - b.y()); - return c; - } - Point operator*(_Tp p) - { - Point c(_x * p, _y * p); - return c; - } - Point operator/(_Tp p) - { - Point c(_x / p, _y / p); - return c; - } - Point &operator+=(Point b) - { - _x += b.x(); - _y += b.y(); - return *this; - } - Point &operator-=(Point b) - { - _x -= b.x(); - _y -= b.y(); - return *this; - } - Point &operator*=(_Tp p) - { - _x *= p; - _y *= p; - return *this; - } - Point &operator/=(_Tp p) - { - _x /= p; - _y /= p; - return *this; - } -}; -const double zero = 1e-12; -int xa, xb, xc, xd, ya, yb, yc, yd; -Point A, B, C, D; -double p,q,r; - -template -_Tp Point <_Tp> ::x() -{ - return _x; -} - -template -_Tp Point <_Tp> ::y() -{ - return _y; -} - -inline double dist(Point a, Point b) -{ - Point tmp = b - a; - return sqrt((tmp.x()*tmp.x()) + (tmp.y() * tmp.y())); -} - -double dist3(Point E, Point F) -{ - return dist(A, E) / p + dist(E, F) / r + dist(F, D) / q; -} - -double calc_F(Point E) -{ - Point l = C, r = D, mid, midmid; - double ans = 1e190; - - while (dist(l, r) > zero) - { - // cout << dist(l, r) << endl; - mid = (l+r)/2; - midmid = (mid+r)/2; - double tp = dist3(E, mid); - double tq = dist3(E, midmid); - //cout <<' '<< tp <<' '< tq) l = mid; - else r = midmid; - if (tp < ans) ans = tp; - if (tq < ans) ans = tq; - } - if (dist(C, D) < zero) ans = dist3(E, C); - return ans; -} - -double calc_E() -{ - Point l = A, r = B, mid, midmid; - double ans = 1e190; - //cout << dist (l, r)<< endl; - while (dist(l, r) > zero) - { - mid = (l+r)/2; - midmid = (mid+r)/2; - double tp = calc_F(mid); - double tq = calc_F(midmid); - //cout << tp <<' '< tq) l = mid; - else r = midmid; - if (tp < ans) ans = tp; - if (tq < ans) ans = tq; - } - if (dist(A, B) < zero) ans = calc_F(A); - return ans; -} - -int main() -{ - scanf("%d%d%d%d%d%d%d%d",&xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd); - scanf("%lf%lf%lf", &p, &q, &r); - A = Point (xa, ya); - B = Point (xb, yb); - C = Point (xc, yc); - D = Point (xd, yd); - printf("%.2lf\n", calc_E()); - return 0; -} diff --git a/hetanglianyi/bzoj1867 b/hetanglianyi/bzoj1867 deleted file mode 100644 index e20728f9..00000000 --- a/hetanglianyi/bzoj1867 +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************** - Problem: 1867 - User: hetanglianyi - Language: C++ - Result: Accepted - Time:8 ms - Memory:1304 kb -****************************************************************/ - -#include -#include -#include -using namespace std; -int n, m; -bool a[60][60]; -long long f[60][60]; -long long gcd(long long a, long long b) -{ - if (b == 0) return a; - return (gcd(b, a % b)); -} -int main() -{ - while (scanf("%d%d", &n, &m) != EOF) - { - char c; - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= i; j++) - { - cin >> c; - if (c == '*') a[i][j] = 1; - else a[i][j] = 0; - } - } - for (int i = 1; i <= n + 1; i++) - a[n + 1][i] = 1; - memset(f, sizeof(f), 0); - f[1][1] = 1LL << (n); - for (int i = 1; i <= n + 1; i++) - { - for (int j = 1; j <= i; j++) - { - // cout << i<<' ' << j<<' '< -#include -#include -#include -#define maxn 400010 -long r[maxn], x[maxn], sa[maxn]; -long wa[maxn], wb[maxn], ws[maxn], wv[maxn], rank[maxn], height[maxn]; -bool v[maxn]; -int name_l[2][maxn], sub_l[maxn]; -int name_p[2][maxn], sub_p[maxn]; -int name_c[maxn], sub_c[maxn], stack[maxn]; -bool marked[maxn]; -int n, m, N, top; - -bool cmp (long *r, long a, long b, long l) -{ - return ((r[a] == r[b]) && (r[a + l] == r[b + l])); -} - - -void calcsa(long *r, long *sa, long n, long m) -{ - long i, j, p, *x = wa, *y = wb, *t; - - for (i = 0; i < m; i++) ws[i] = 0; - for (i = 0; i < n; i++) ws[x[i] = r[i]]++; - for (i = 1; i < m; i++) ws[i] += ws[i - 1]; - for (i = n - 1; i >= 0; i--) sa[--ws[x[i]]] = i; - - for (j = 1, p = 1; p < n; j *= 2, m = p) - { - for (p = 0, i = n - j; i < n; i++) y[p++] = i; - for (i = 0; i < n; i++) if (sa[i] - j >= 0) y[p++] = sa[i] - j; - - for (i = 0; i < n; i++) wv[i] = x[y[i]]; - for (i = 0; i < m; i++) ws[i] = 0; - for (i = 0; i < n; i++) ws[wv[i]]++; - for (i = 1; i < m; i++) ws[i] += ws[i - 1]; - for (i = n - 1; i >= 0;i--) sa[--ws[wv[i]]] = y[i]; - - t = x; x = y; y = t; - p = 1; x[sa[0]] = 0; - for (i = 1; i < n ; i++) - { - x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++; - } - } - } -void calcheight(long *r, long *sa, long n) -{ - long i, j, p; - for (i = 1; i <= n; i++) - rank[sa[i]] = i; - p = 0; - for (i = 0; i < n; i++) - { - j = sa[rank[i] - 1]; - while (r[i + p] == r[j + p]) - p++; - height[rank[i]] = p; - if (p > 0) p--; - } - return; -} - - -inline int find(int x) -{ - if (x < name_p[1][0]) return 0; - int L = 1, R = n - 1; - while (L < R + 1) - { - int Mid = L + R >> 1; - if (x < name_p[1][Mid] && - x > name_p[1][Mid - 1]) - return Mid; - if (x > name_p[1][Mid]) L = Mid + 1; - else R = Mid - 1; - } - return -1; -} - -int main() -{ - - scanf("%d%d", &n, &m); - N = 0; - for (int i = 0; i < n; i++) - { - scanf("%d", &name_l[0][i]); - for (int j = 0; j < name_l[0][i]; j++) - { - int tmp; - scanf("%d", &tmp); - r[N++] = tmp + 1; - } - r[name_p[0][i] = (N++)] = 0; - - scanf("%d", &name_l[1][i]); - for (int j = 0; j < name_l[1][i]; ++j) - { - int tmp; - scanf("%d", &tmp); - r[N++] = tmp + 1; - } - r[name_p[1][i] = (N++)] = 0; - } - for (int i = 0; i < m; i++) - { - scanf("%d", &sub_l[i]); - for (int j = 0; j < sub_l[i]; j++) - { - int tmp; - scanf("%d", &tmp); - r[N++] = tmp + 1; - } - r[sub_p[i] = (N++)] = 0; - } - calcsa(r, sa, N--, 10010); - calcheight(r, sa, N); - for (int i = 0; i < m; i++) - { - int pos = rank[sub_p[i] - sub_l[i]]; - top = 0; - for (int j = pos; j; j--) - { - if (height[j] < sub_l[i]) break; - int tmp = find(sa[j - 1]); - if (tmp + 1) - { - if (!marked[tmp]) ++name_c[stack[top++] = tmp], ++sub_c[i]; - marked[tmp] = 1; - } - } - for (int j = pos + 1; j < N + 1; j++) - { - if (height[j] < sub_l[i]) break; - int tmp = find(sa[j]); - if (tmp + 1) - { - if (!marked[tmp]) ++name_c[stack[top++] = tmp], ++sub_c[i]; - marked[tmp] = 1; - } - } - for (int j = 0; j < top; j++) - marked[stack[j]] = 0; - } - for (int i = 0; i < m; i++) - printf("%d\n", sub_c[i]); - for (int i = 0; i < n; i++) - printf("%d ", name_c[i]); - printf("\n"); - return 0; -} diff --git a/jkrs/VK_CUP_2016_A.cpp b/jkrs/VK_CUP_2016_A.cpp deleted file mode 100644 index cebacdec..00000000 --- a/jkrs/VK_CUP_2016_A.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define pu system("pause") -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; - -const double pi = acos(-1.0); -const int inf = 0x7fffffff; -const int mod = 1e9 + 7; - -int h[5010],ans[5010]; - -int a[5010]; - -int main() -{ - int n; - scanf("%d",&n); - for (int i = 1;i <= n ;++ i) - { - scanf("%d",&a[i]); - } - - for (int i = 1;i <= n; ++ i) - { - memset(h,0,sizeof (h)); - int maxn = 0; - int cur = 0; - for (int j = i;j <= n; ++ j) - { - ++ h[a[j]]; - if (h[a[j]] > maxn || (h[a[j]] == maxn && cur > a[j])) - { - maxn = h[a[j]]; - cur = a[j]; - } - ++ ans[cur]; - } - - } - for (int i = 1;i <= n; ++ i) - { - printf("%d%c",ans[i],i == n ? '\n' : ' '); - } - return 0; -} diff --git a/jkrs/cf670_e.cpp b/jkrs/cf670_e.cpp deleted file mode 100644 index d5f107b4..00000000 --- a/jkrs/cf670_e.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define pu system("pause") -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; - -const double pi = acos(-1.0); -const int inf = 0x7fffffff; -const int mod = 1e9 + 7; - -list l; - -char s[500010],cmd[500010]; - -int main() -{ - int n,m,st; - scanf("%d%d%d",&n,&m,&st); - scanf("%s",s); - scanf("%s",cmd); - for (int i = 0;s[i]; ++ i) - l.push_back(s[i]); - list :: iterator it = l.begin(); - advance(it,st - 1); -// printf("cur it = %c\n",*it); - for (int i = 0;cmd[i]; ++ i) - { -// printf("cmd[%d] = %c it = %c\n",i,cmd[i],*it); - if (cmd[i] == 'R') - { - ++ it; - if (it == l.end()) - it = l.begin(); - - } - - else if (cmd[i] == 'L') - { - - if (it == l.begin()) - it = l.end(); - else - -- it; - } - else - { - if (*it == '(') - { -// puts("1"); - int flag = 1; - it = l.erase(it); - while (it != l.end() && flag != 0) - { - if (*it == ')') - -- flag; - else - ++ flag; - it = l.erase(it); - } - } - else if (*it == ')') - { -// printf("2\n"); - int flag = -1; -// printf("cur %c\n",*it); - it = l.erase(it); -// printf("then it = %c\n",*it); -// printf("then cur it = %c\n",*it); - while (it != l.begin() && flag != 0) - { - -- it; - - if (*it == ')') - -- flag; - else - ++ flag; - it = l.erase(it); - -// printf("flag = %d %c\n",flag,*it); - } - } - if (it == l.end()) - -- it; - } -// for (list :: iterator it2 = l.begin();it2 != l.end(); ++ it2) -// printf("%c",*it2); -// puts(""); - } - for (it = l.begin();it != l.end(); ++ it) - printf("%c",*it); - - puts(""); - return 0; -} diff --git a/jkrs/cf_673_b.cpp b/jkrs/cf_673_b.cpp deleted file mode 100644 index 375e323c..00000000 --- a/jkrs/cf_673_b.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define pu system("pause") -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; - -const double pi = acos(-1.0); -const ll inf = 0x7fffffff; -const ll mod = 1e9 + 7; - -int main() -{ - int n,m; - scanf("%d%d",&n,&m); - int maxn = inf,minn = 0; - for (int i = 0;i < m; ++ i) - { - int x,y; - scanf("%d%d",&x,&y); - if (x > y) - { - maxn = min(maxn,x); - minn = max(minn,y); - } - else - { - maxn = min(maxn,y); - minn = max(minn,x); - } - } - if (!m) - { - printf("%d\n",n - 1); - return 0; - } - printf("%d\n",maxn - minn >= 0 ? maxn - minn : 0); - return 0; -} diff --git a/jkrs/cf_673_d.cpp b/jkrs/cf_673_d.cpp deleted file mode 100644 index 514a3c72..00000000 --- a/jkrs/cf_673_d.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define pu system("pause") -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; - -const double pi = acos(-1.0); -const int inf = 0x7fffffff; -const int mod = 1e9 + 7; - -bool h[1010]; - -int main() -{ - int n,k,a,b,c,d; - scanf("%d%d%d%d%d%d",&n,&k,&a,&b,&c,&d); - for (int i = 1;i <= n; ++ i) - h[i] = 1; - h[a] = h[b] = h[c] = h[d] = 0; - if (n + 1 > k) - puts("-1"); - else if (n == 4) - { - puts("-1"); - } - else - { - printf("%d %d ",a,c); - for (int i = 1;i <= n; ++ i) - if (h[i]) - printf("%d ",i); - printf("%d %d\n",d,b); - printf("%d %d ",c,a); - for (int i = 1;i <= n; ++ i) - if (h[i]) - printf("%d ",i); - printf("%d %d\n",b,d); - } - return 0; -} diff --git a/jkrs/cf_674_b.cpp b/jkrs/cf_674_b.cpp deleted file mode 100644 index 788e416d..00000000 --- a/jkrs/cf_674_b.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define pu system("pause") -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; - -const ll inf = 0x7fffffff; -const double pi = acos(-1.0); -const ll mod = 1e9 + 7; - -char s[100010]; - -bool h[30]; - -int main() -{ - int n; - scanf("%d",&n); - scanf("%s",s); - if (n > 26) - puts("-1"); - else - { - int ans = 0; - for (int i = 0;s[i]; ++ i) - h[s[i] - 'a'] = 1; - for (int i = 0;i < 26; ++ i) - if (h[i]) - ++ ans; - printf("%d\n",n - ans); - } - return 0; -} diff --git a/jkrs/cf_674_c.cpp b/jkrs/cf_674_c.cpp deleted file mode 100644 index 9c1b0fae..00000000 --- a/jkrs/cf_674_c.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace std; -double ax,ay,bx,by,tx,ty; -double ans,x[100005],y[100005],len[100005],dp[100005][3]; -int n; -int main() -{ - scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty); - scanf("%d",&n); - for(int i=1;i<=n;++i) - scanf("%lf%lf",x+i,y+i), - len[i]=sqrt((x[i]-tx)*(x[i]-tx)+(y[i]-ty)*(y[i]-ty)), - ans+=len[i]; - ans*=2; - dp[0][0]=dp[0][1]=dp[0][2]=-1e100; - for(int i=1;i<=n;++i) - { - double ta=sqrt((x[i]-ax)*(x[i]-ax)+(y[i]-ay)*(y[i]-ay)); - double tb=sqrt((x[i]-bx)*(x[i]-bx)+(y[i]-by)*(y[i]-by)); - dp[i][0]=max(dp[i-1][0],len[i]-ta); - dp[i][1]=max(dp[i-1][1],len[i]-tb); - dp[i][2]=max(len[i]-ta+dp[i-1][1],len[i]-tb+dp[i-1][0]); - dp[i][2]=max(dp[i][2],dp[i-1][2]); - } - ans-=max(dp[n][0],max(dp[n][1],dp[n][2])); - printf("%.15lf\n",ans); - return 0; -} diff --git a/lucky/helloworld b/lucky/helloworld deleted file mode 100644 index 5b2c9a89..00000000 --- a/lucky/helloworld +++ /dev/null @@ -1,5 +0,0 @@ -#include -int main(){ - printf("hello,world\n"); - return 0; -} diff --git a/lucky/lucky.cpp b/lucky/lucky.cpp deleted file mode 100644 index 07e37071..00000000 --- a/lucky/lucky.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include -#include -#define LL long long -using namespace std; -const int maxn=1<<30; -const int SIZE=1e2+10; -int cmap[20][20],dp[17][70000]; -int main() -{ - int T,n; - scanf("%d",&T); - for(int cas=1;cas<=T;cas++){ - scanf("%d",&n); - for(int i=1;i<=n;i++) - for(int j=1;j<=n;j++) - scanf("%d",&cmap[i][j]); - memset(dp,0,sizeof(dp)); - for(int i=1;i<=n;i++){//第i行枚举前i-1行状态j - for(int j=0;j<(1< -using namespace std; -int n,m,x,y,maxn,maxsav; -int a[5005]; -int b[5005]; -int sav[5005]; -int main() -{ - scanf("%d",&n); - for(int i=1;i<=n;i++) - { - scanf("%d",a+i); - } - for(int i=1;i<=n;i++) - { - memset(sav,0,sizeof(sav)); - maxsav=a[i]; - maxn=1; - b[a[i]]++; - sav[a[i]]++; - for(int j=i+1;j<=n;j++) - { - sav[a[j]]++; - if(sav[a[j]]>=maxn) - { - if(sav[a[j]]==maxn) - maxsav=min(a[j],maxsav); - else - maxsav=a[j]; - maxn=sav[a[j]]; - } - b[maxsav]++; - } - } - for(int i=1;i<=n;i++) - printf("%d ",b[i]); -} diff --git a/thunderMrbird/2016-5-11.cpp b/thunderMrbird/2016-5-11.cpp deleted file mode 100644 index ea756406..00000000 --- a/thunderMrbird/2016-5-11.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -char a[105],b[105]; -int ans[105]; -stack stk; -int main() -{ - int m; - while(scanf("%d",&m)!=EOF) - { - int i=0,j=0,t=0; - scanf("%s",a); - scanf("%s",b); - while(!stk.empty()) - stk.pop(); - while(j -using namespace std; -char a[100005]; -mapmp; -int main() -{ - int tt=0,m,n,T,ans=0; - scanf("%d",&n); - scanf("%s",a); - for(int i=0;i1) ans++; - } - printf("%d\n",ans>26-mp.size()?-1:ans); - return 0; -} diff --git a/thunderMrbird/2016-5-13.cpp b/thunderMrbird/2016-5-13.cpp deleted file mode 100644 index acd638d0..00000000 --- a/thunderMrbird/2016-5-13.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; -string s; -int main() -{ - int tt=0,m,n,T,ans=0; - cin>>s; - for(int i=1;i -using namespace std; -int n; -setst; -setv[100010]; -int main() -{ - string s; - cin>>s; - int n=s.size(); - for(int i=n-1;i>4;i--){ - string t=s.substr(i,1); - for(int j=i-1;j>=i-2&&j>4;j--){ - t=s[j]+t; - if(v[i+1].size() == 1 && !v[i+1].count(t) || v[i+1].size()>1 ||i + 1 >= n){ - v[j].insert(t); - st.insert(t); - } - } - } - cout< -using namespace std; -typedef long long ll; -int a[100005],b[100005]; -int main() -{ - int n; - ll k; - scanf("%d %I64d",&n,&k); - for(int i=0;i>1; - for(int i=0;ik) break; - } - if(sum<=k) - l=mid; - else - r=mid-1; - } - //printf("%I64d %I64d ",r,mid); - printf("%I64d",l); - return 0; -} diff --git a/thunderMrbird/2016-5-8.cpp b/thunderMrbird/2016-5-8.cpp deleted file mode 100644 index 3e3fba59..00000000 --- a/thunderMrbird/2016-5-8.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -using namespace std; -typedef long long ll; -char a[500005],op[500005]; -list lst; -int main() -{ - int n,m,p; - scanf("%d %d %d",&n,&m,&p); - scanf("%s",a); - scanf("%s",op); - for (int i = 0; i < n; ++i) - lst.push_back(i); - auto it = lst.begin(); - while(--p) - ++it; - for(int i=0;i -using namespace std; -int n,m,x,y; -int main() -{ - scanf("%d %d",&n,&m); - int l=1,r=n; - for(int i=0;iy) swap(x,y); - l=max(l,x); - r=min(r,y); - } - if(l>r) printf("0"); - else printf("%d",r-l); -} diff --git a/winterfell30/2016_05_06.cpp b/winterfell30/2016_05_06.cpp deleted file mode 100644 index 9617b909..00000000 --- a/winterfell30/2016_05_06.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define Lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int MOD = 1000000007; -const int maxn = 1e5 + 10; -const double eps = 1e-8; -const double PI = acos(-1.0); -typedef pair pii; - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - LL s, x; - cin >> s >> x; - if (s < x || (s - x) & 1) - return puts("0"); - LL And = (s - x) >> 1; - if (x & And) return puts("0"); - LL ans = s == x ? -2 : 0; - int cnt = 0; - while (x) - { - if (x & 1) cnt++; - x >>= 1; - } - ans += 1LL << cnt; - cout << ans << endl; - return 0; -} diff --git a/winterfell30/2016_05_07.cpp b/winterfell30/2016_05_07.cpp deleted file mode 100644 index d5ce1aa3..00000000 --- a/winterfell30/2016_05_07.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int MOD = 1000000007; -const int maxn = 1e5 + 10; -const double eps = 1e-8; -const double PI = acos(-1.0); -typedef pair pii; - -LL sum[2*maxn][2]; -int now[2*maxn]; - -void add(int x, int val1, int val2) -{ - while (x < (maxn << 1)) - { - sum[x][0] += val1; - sum[x][1] += val2; - x += lowbit(x); - } -} - -LL query(int t, int x) -{ - LL res = 0; - while (x > 0) - { - res += sum[x][t]; - x -= lowbit(x); - } - return res; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - int n, a, b, k, q; - cin >> n >> k >> b >> a >> q; - while (q--) - { - int t, d, order; - cin >> t; - if (t == 1) - { - cin >> d >> order; - int pre = now[d]; - now[d] += order; - int or0 = min(now[d], a) - min(pre, a); - int or1 = min(now[d], b) - min(pre, b); - add(d, or0, or1); - } - else - { - cin >> d; - LL ans = query(0, d - 1) + query(1, n) - query(1, d + k - 1); - cout << ans << endl; - } - } - return 0; -} diff --git a/winterfell30/2016_05_08.cpp b/winterfell30/2016_05_08.cpp deleted file mode 100644 index ce1f51f7..00000000 --- a/winterfell30/2016_05_08.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int MOD = 1000000007; -const int maxn = 1e5 + 10; -const double eps = 1e-8; -const double PI = acos(-1.0); -typedef pair pii; -LL dp[1<<20][20]; -bool a[20][20]; - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - int n, m, u, v; - cin >> n >> m; - for (int i = 0; i < m; i++) - { - cin >> u >> v; - u--, v--; - a[u][v] = a[v][u] = 1; - } - memset(dp, 0, sizeof(dp)); - for (int i = 0; i < n; i++) - dp[1<= 3) - ans += dp[s][e]; - } - } - cout << ans / 2 << endl; - return 0; -} diff --git a/winterfell30/2016_05_09.cpp b/winterfell30/2016_05_09.cpp deleted file mode 100644 index 80012244..00000000 --- a/winterfell30/2016_05_09.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define Lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int maxn = 1e5 + 7; -const double eps = 1e-8; -const double PI = acos(-1.0); -struct node -{ - int l, r; - int t; -}a[maxn]; - -int sum[maxn<<2]; -int col[maxn<<2]; - -map H1, H2; - -void PushUp(int rt) -{ - sum[rt] = sum[rt<<1] + sum[rt<<1|1]; -} - -void PushDown(int rt, int m) -{ - if (col[rt]) - { - col[rt<<1] = col[rt<<1|1] = col[rt]; - sum[rt<<1] = 0; - sum[rt<<1|1] = 0; - col[rt] = 0; - } -} - -void build(int l, int r, int rt) -{ - col[rt] = 0; - sum[rt] = 0; - if (l == r) - { - sum[rt] = H2[l+1] - H2[l]; - return ; - } - int mid = (l + r) >> 1; - build(lson); - build(rson); - PushUp(rt); -} - -void update(int L, int R, int val, int l, int r, int rt) -{ - if (L <= l && r <= R) - { - col[rt] = 1; - sum[rt] = 0; - return ; - } - //cout << l << " " << r << endl; - PushDown(rt, r - l + 1); - int mid = (l + r) >> 1; - if (L <= mid) update(L, R, val, lson); - if (R > mid) update(L, R, val, rson); - PushUp(rt); -} - -int query(int L, int R, int l, int r, int rt) -{ - if (L <= l && r <= R) - { - return sum[rt]; - } - PushDown(rt, r - l + 1); - int mid = (l + r) >> 1; - int ans = 0; - if (L <= mid) ans += query(L, R, lson); - if (R > mid) ans += query(L, R, rson); - return ans; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - int n, q; - while (scanf("%d%d", &n, &q) != EOF) - { - vector v; - for (int i = 0; i < q; i++) - { - scanf("%d%d%d", &a[i].t, &a[i].l, &a[i].r); - v.push_back(a[i].l), v.push_back(a[i].r); - if (a[i].l != 1) v.push_back(a[i].l - 1); - v.push_back(a[i].r + 1); - } - v.push_back(n + 1); - sort(v.begin(), v.end()); - v.erase(unique(v.begin(), v.end()), v.end()); - for (int i = 0; i < v.size(); i++) - H1[v[i]] = i + 1, H2[i + 1] = v[i]; - build(1, v.size(), 1); - for (int i = 0; i < q; i++) - { - if (a[i].t == 1) - update(H1[a[i].l], H1[a[i].r], 0, 1, v.size(), 1); - else - printf("%d\n", query(H1[a[i].l], H1[a[i].r], 1, v.size(), 1)); - } - } - return 0; -} diff --git a/winterfell30/2016_05_10.cpp b/winterfell30/2016_05_10.cpp deleted file mode 100644 index b6042bf3..00000000 --- a/winterfell30/2016_05_10.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define Lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int maxn = 1e6 + 7; -const double eps = 1e-8; -const double PI = acos(-1.0); -LL sum[maxn]; -bool vis[maxn]; -vector prime; - -void init() -{ - for (int i = 2; i * i <= maxn; i++) if (!vis[i]) - { - prime.push_back(i); - for (int j = i * 2; j <= maxn; j += i) - vis[j] = 1; - } -} - -int solve(int n) -{ - int res; - int cnt = 0; - for (int i = 2; i * i <= n; i++) if (n % i == 0) - { - cnt++, res = i; - while (n % i == 0) n /= i; - if (cnt > 1) return 1; - } - if (n > 1) cnt++; - if (cnt > 1) return 1; - else return res; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - - int n; - init(); - sum[2] = 0; - for (int i = 3; i <= maxn; i++) //素数为n,一个质因子为p,多个质因子为1 - if (!vis[i]) sum[i] = sum[i-1] + i; - else sum[i] = sum[i-1] + solve(i); - while (cin >> n) - { - cout << sum[n] << endl; - } - return 0; -} diff --git a/winterfell30/2016_05_11.cpp b/winterfell30/2016_05_11.cpp deleted file mode 100644 index 4504cfa7..00000000 --- a/winterfell30/2016_05_11.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define Lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int MOD = 1000000007; -const int maxn = 1e5 + 10; -const double eps = 1e-8; -const double PI = acos(-1.0); -typedef pair pii; - -const int S = 20; - -LL q_mul(LL a, LL b, LL p) -{ - a %= p; - b %= p; - LL res = 0; - while (b) - { - if (b & 1) res = (res + a) % p; - a <<= 1; - if (a >= p) a %= p; - b >>= 1; - } - return res; -} - -LL q_pow(LL x, LL n, LL mod) -{ - LL temp = x; - LL res = 1; - while (n) - { - if (n & 1) res = q_mul(res, temp, mod); - temp = q_mul(temp, temp, mod); - n >>= 1; - } - return res; -} - - -//判断是不是一定是合数 -bool check(LL a, LL n, LL x, LL t) -{ - LL res = q_pow(a, x, n); - LL last = res; - for (int i = 1; i <= t; i++) - { - res = q_mul(res, res, n); - if (res == 1 && last != 1 && last != n - 1) //二次检测 - return 1; - last = res; - } - if (res != 1) return 1; - return 0; -} - -bool Miller_Rabin(LL n) -{ - if (n < 2) return 0; - if (n == 2) return 1; - if (!(n & 1)) return 0; - LL x = n - 1; - LL t = 0; - while ((x & 1) == 0) - x >>= 1, t++; - for (int i = 0; i < S; i++) - { - LL a = rand() % (n - 1) + 1; - if (check(a, n, x, t)) - return 0; //合数 - } - return 1; //伪素数 -} - - - -LL factor[110]; //无序质因子 -int tot; - -LL Pollard_rho(LL x, LL c) -{ - LL i = 1, k = 2; - LL x0 = rand() % x; - LL y = x0; - while (1) - { - i++; - x0 = (q_mul(x0, x0, x) + c) % x; - LL d = __gcd(y - x0 + x, x); //一定要注意+x,或者在gcd里面加上负数判断 - if (d != 1 && d != x) return d; - if (y == x0) return x; - if (i == k) { y = x0; k += k;} - } -} - -void findfac(LL n) -{ - if (Miller_Rabin(n)) - { - factor[tot++] = n; - return ; - } - LL p = n; - while (p >= n) - p = Pollard_rho(p, rand() % (n - 1) + 1); - findfac(p); - findfac(n / p); -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - int T; - scanf("%d", &T); - while (T--) - { - LL n; - scanf("%lld", &n); - if (Miller_Rabin(n)) - puts("Prime"); - else - { - tot = 0; - findfac(n); - LL ans = factor[0]; - for (int i = 1; i < tot; i++) - ans = min(ans, factor[i]); - printf("%lld\n", ans); - } - } - return 0; -} diff --git a/winterfell30/2016_05_12.cpp b/winterfell30/2016_05_12.cpp deleted file mode 100644 index a3056863..00000000 --- a/winterfell30/2016_05_12.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define Lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int MOD = 1000000007; -const int maxn = 1e5 + 10; -const double eps = 1e-8; -const double PI = acos(-1.0); -typedef pair pii; - -struct node -{ - double sub; //bin - p - int id; -}; -node a[maxn], b[maxn]; -int cmp(node x, node y) -{ - return ((x.sub - y.sub) > eps); -} - -double dist(double x1, double y1, double x2, double y2) -{ - return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - double x1, y1, x2, y2, tx, ty; - scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &tx, &ty); - int n; - scanf("%d", &n); - double sum = 0; - for (int i = 0; i < n; i++) - { - double x, y; - scanf("%lf%lf", &x, &y); - sum += 2 * dist(x, y, tx, ty); - double bin = dist(x, y, tx, ty); - a[i].sub = bin - dist(x, y, x1, y1); - b[i].sub = bin - dist(x, y, x2, y2); - a[i].id = i; - b[i].id = i; - } - sort(a, a + n, cmp); - sort(b, b + n, cmp); - double ans = INF; - ans = min(sum - a[0].sub, sum - b[0].sub); - if (a[0].id == b[0].id) - ans = min(ans, sum - max(a[0].sub + b[1].sub, a[1].sub + b[0].sub)); - else ans = min(ans, sum - (a[0].sub + b[0].sub)); - printf("%.10f\n", ans); - return 0; -} diff --git a/winterfell30/2016_05_13.cpp b/winterfell30/2016_05_13.cpp deleted file mode 100644 index 79947932..00000000 --- a/winterfell30/2016_05_13.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define LL long long -#define lowbit(x) ((x)&(-x)) -#define lson l, mid, rt << 1 -#define rson mid + 1, r, rt << 1|1 -#define MP(a, b) make_pair(a, b) -const int INF = 0x3f3f3f3f; -const int MOD = 1000000007; -const int maxn = 1e5 + 10; -const double eps = 1e-8; -const double PI = acos(-1.0); -typedef pair pii; -LL c[5*maxn]; -LL n, k; - -bool check2(int x) -{ - LL sum = 0; - for (int i = n-1; i >= 0; i--) - if (c[i] > x) sum += (c[i] - x); - return sum <= k; -} - -bool check1(int x) -{ - LL sum = 0; - for (int i = 0; i < n; i++) - if (c[i] < x) sum += (x - c[i]); - return sum <= k; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - LL sum = 0; - scanf("%lld%lld", &n, &k); - for (int i = 0; i < n; i++) - { - scanf("%lld", &c[i]); - sum += c[i]; - } - sort(c, c + n); - LL mmin = sum / n; //最小值最大 - LL mmax = mmin + (sum % n != 0); //最大值最小 - LL l = c[0], r = mmin; - while (l < r) //k天后的最小值 - { - int mid = (l + r + 1) / 2; - //printf("%d\n", mid); - if (check1(mid)) l = mid; - else r = mid - 1; - } - LL ansmin = l; - l = mmax, r = c[n-1]; - while (l < r) - { - int mid = (l + r) / 2; - if (check2(mid)) r = mid; - else l = mid + 1; - } - LL ansmax = l; - //printf("%lld %lld\n", ansmin, ansmax); - printf("%lld\n", ansmax - ansmin); - return 0; -} diff --git "a/winterfell30/\345\215\232\345\256\242\345\234\260\345\235\200.md" "b/winterfell30/\345\215\232\345\256\242\345\234\260\345\235\200.md" deleted file mode 100644 index debb3f43..00000000 --- "a/winterfell30/\345\215\232\345\256\242\345\234\260\345\235\200.md" +++ /dev/null @@ -1 +0,0 @@ -个人主页: http://winterfell30.com diff --git a/wuyiqi/Gauss.cpp b/wuyiqi/Gauss.cpp deleted file mode 100644 index d26ff7d1..00000000 --- a/wuyiqi/Gauss.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include -using namespace std; - -const double eps = 1e-8; -struct Gauss -{ - int equation, variable; - double a[27][11], ret[10]; - void Init() { - equation = 27; - variable = 10; - memset(a, 0, sizeof(a)); - } - - bool Eliminate() { - int col = 0, row = 0; - for(; row < equation && col < variable; row++, col++) { - int max_row = row; - for(int i = row + 1; i < equation; i++) { - if(fabs(a[i][col]) > fabs(a[max_row][col])) { - max_row = i; - } - } - - if(fabs(a[max_row][col]) < eps) { - row--; - continue; - } - - if(max_row != row) { - for(int i = col; i <= variable; i++) { - swap(a[max_row][i], a[row][i]); - } - } - - for(int i = 0; i < equation; i++) if(i!=row){ - if(fabs(a[i][col]) < eps) { - continue; - } - double ta = a[row][col]; - double tb = a[i][col]; - for(int j = col; j <= variable; j++) { - a[i][j] = a[i][j] - a[row][j] * tb / ta; - } - } - } - /* - for(int i = 0; i < 27; i++) { - for(int j = 0; j <= 10; j++) { - printf("%.0f ", a[i][j]); - } - puts(""); - } - */ - for(int i = row; i < equation; i++) { - if(fabs(a[i][variable]) > eps) { - return false; - } - } - for(int i = 0; i < row; i++) { - ret[i] = a[i][variable] / a[i][i]; - } - for(int i = row; i < variable; i++) { - ret[i] = 0; - } - return true; - } -}gauss; - - -string num[10] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE" }; - -int main() -{ - freopen("A-large-practice.in", "r", stdin); - freopen("A.out", "w", stdout); - int T, ca = 1; - cin >> T; - string s; - while(T--) { - cin >> s; - int cnt[26]; - memset(cnt, 0, sizeof(cnt)); - for(int i = 0; i < s.length(); i++) { - cnt[s[i]-'A']++; - } - map edge[26]; - for(int i = 0; i < 10; i++) { - for(auto it : num[i]) { - edge[it-'A'][i]++; - } - } - gauss.Init(); - for(int i = 0; i < 26; i++) { - for(auto it : edge[i]) { - gauss.a[i][it.first] = it.second; - } - gauss.a[i][10] = cnt[i]; - } - for(int i = 0; i < 10; i++) { - gauss.a[26][i] = (int)num[i].length(); - } - gauss.a[26][10] = (int)s.length(); - bool flag = gauss.Eliminate(); - cout << "Case #" << ca++ << ": "; - for(int i = 0; i < 10; i++) { - int cnt = (int)(gauss.ret[i]+0.5); - for(int j = 0; j < cnt; j++) { - printf("%c", '0'+i); - } - } - cout << endl; - } - return 0; -} diff --git a/wuyiqi/README.md b/wuyiqi/README.md deleted file mode 100644 index b02def2d..00000000 --- a/wuyiqi/README.md +++ /dev/null @@ -1,2 +0,0 @@ -test -test2 diff --git a/wuyiqi/TCO_2016_2A/LCMGCD.cpp b/wuyiqi/TCO_2016_2A/LCMGCD.cpp deleted file mode 100644 index 1a95dfc5..00000000 --- a/wuyiqi/TCO_2016_2A/LCMGCD.cpp +++ /dev/null @@ -1,281 +0,0 @@ -// Paste me into the FileEdit configuration dialog -// Paste me into the FileEdit configuration dialog - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -typedef long long LL; -using namespace std; - - -class LCMGCD -{ -public: - string isPossible( vector x, int t ) ; -}; -int s[3][3]; -int Get(int a, int b) -{ - if(a < b) return 0; - if(a == b) return 1; - return 2; -} -bool dp[10][1 << 9]; -string LCMGCD:: isPossible( vector x, int t ) -{ - int A = 0; while(t % 2 == 0) {t/=2;A++;} - int B = 0; while(t % 3 == 0) {t/=3;B++;} - memset(s, 0, sizeof(s)); - for(int num : x) { - int a = 0; while(num % 2 == 0) {num/=2;a++;} - int b = 0; while(num % 3 == 0) {num/=3;b++;} - s[Get(a, A)][Get(b, B)]++; - } - if(s[1][1] >= 2) { - return "Possible"; - } - memset(dp, false, sizeof(dp)); - vector > pts; - int mp[3][3]; - int p[9][2]; - int tot = 0; - for(int i = 0; i < 3; i++) { - for(int j = 0; j < 3; j++) { - p[tot][0] = i; - p[tot][1] = j; - mp[i][j] = tot++; - if(s[i][j]) { - pts.push_back(make_pair(i, j)); - } - } - } - int n = (int)pts.size(); - int mask = 0; - for(auto num : pts){ - mask |= 1 << mp[num.first][num.second]; - } - dp[n][mask] = true; - for(int i = n; i >= 2; i--) { - for(int mask = 0; mask < 1 << 9; mask++) if(dp[i][mask]) { - for(int j = 0; j < 9; j++) { - for(int k = j + 1; k < 9; k++)if((mask >> j & 1) && (mask >> k & 1)) { - int x = p[j][0], y = p[j][1]; - int tx = p[k][0], ty = p[k][1]; - int nmask = mask ^ (1 << j) ^ (1 << k); - int nx = min(x, tx), ny = min(y, ty); - dp[i - 1][nmask | (1 << mp[nx][ny])] = true; - - nx = max(x, tx), ny = max(y, ty); - dp[i - 1][nmask | (1 << mp[nx][ny])] = true; - } - } - } - } - if(dp[1][1 << mp[1][1]] == true) return "Possible"; - return "Impossible"; -} -// BEGIN CUT HERE -namespace moj_harness { - int run_test_case(int); - void run_test(int casenum = -1, bool quiet = false) { - if ( casenum != -1 ) { - if ( run_test_case( casenum ) == -1 && !quiet ) - cerr << "Illegal input! Test case " << casenum << " does not exist." << endl; - return; - } - - int correct = 0, total = 0; - for ( int i=0;; ++i ) { - int x = run_test_case(i); - if ( x == -1 ) { - if ( i >= 100 ) break; - continue; - } - correct += x; - ++total; - } - - if ( total == 0 ) { - cerr << "No test cases run." << endl; - } else if ( correct < total ) { - cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << endl; - } else { - cerr << "All " << total << " tests passed!" << endl; - } - } - - int verify_case(int casenum, const string &expected, const string &received, clock_t elapsed) { - cerr << "Example " << casenum << "... "; - - string verdict; - vector info; - char buf[100]; - - if (elapsed > CLOCKS_PER_SEC / 200) { - sprintf(buf, "time %.2fs", elapsed * (1.0/CLOCKS_PER_SEC)); - info.push_back(buf); - } - - if ( expected == received ) { - verdict = "PASSED"; - } else { - verdict = "FAILED"; - } - - cerr << verdict; - if (!info.empty()) { - cerr << " ("; - for (int i=0; i<(int)info.size(); ++i) { - if (i > 0) cerr << ", "; - cerr << info[i]; - } - cerr << ")"; - } - cerr << endl; - - if (verdict == "FAILED") { - cerr << " Expected: \"" << expected << "\"" << endl; - cerr << " Received: \"" << received << "\"" << endl; - } - - return verdict == "PASSED"; - } - - int run_test_case( int casenum ) { - switch( casenum ) { - case 0: { - int x[] = {2,3}; - int t = 6; - string expected__ = "Possible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 1: { - int x[] = {4,9}; - int t = 6; - string expected__ = "Impossible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 2: { - int x[] = {6,12,24,18,36,72,54,108,216}; - int t = 36; - string expected__ = "Possible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 3: { - int x[] = {6,27,81,729}; - int t = 6; - string expected__ = "Impossible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 4: { - int x[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; - int t = 1; - string expected__ = "Possible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 5: { - int x[] = {72,16,16,16,16,16,27,27,27,27,27,27,27,27,27}; - int t = 72; - string expected__ = "Possible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 6: { - int x[] = {100663296, 544195584, 229582512, 59049}; - int t = 60466176; - string expected__ = "Possible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - case 7: { - int x[] = {2,4,8,16,32,64}; - int t = 256; - string expected__ = "Impossible"; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - } - - // custom cases - - /* case 8: { - int x[] = ; - int t = ; - string expected__ = ; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - }*/ - /* case 9: { - int x[] = ; - int t = ; - string expected__ = ; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - }*/ - /* case 10: { - int x[] = ; - int t = ; - string expected__ = ; - - clock_t start__ = clock(); - string received__ = LCMGCD().isPossible( vector ( x, x + ( sizeof x / sizeof x[0] ) ), t ); - return verify_case( casenum, expected__, received__, clock()-start__ ); - }*/ - default: - return -1; - } - } -} - - -int main(int argc, char *argv[]) { - if (argc == 1) { - moj_harness::run_test(); - } else { - for (int i=1; i - -const int N = 500010; -char s[N], op[N]; -int main() -{ - int n, m, p; - scanf("%d%d%d", &n, &m, &p); - scanf("%s", s); - std::list list; - for(int i = 0; s[i]; i++) { - list.push_back(s[i]); - } - auto it = list.begin(); - for(int i = 1; i < p; i++) it++; - scanf("%s", op); - for(int i = 0; op[i]; i++) { - if(op[i] == 'L') { - --it; - } else if(op[i] == 'R'){ - ++it; - } else { - if(*it == '(') { - it = list.erase(it); - int cnt = 1; - while(cnt > 0) { - cnt += (*it == '(') * 2 - 1; - it = list.erase(it); - } - } else { - it = list.erase(it); - int cnt = 1; - while(cnt > 0) { - cnt += (*--it == ')') * 2 - 1; - it = list.erase(it); - } - } - if(it == list.end()) --it; - } - } - for(auto it : list) - putchar(it); - puts(""); - return 0; -} diff --git a/wuyiqi/cf350/F.cpp b/wuyiqi/cf350/F.cpp deleted file mode 100644 index 6505c8bf..00000000 --- a/wuyiqi/cf350/F.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include - -std::string s, t, ret; -std::vector candidates; -int cnt[10]; -void PushBackAll(int i) -{ - for(int j = 0; j < cnt[i]; j++) { - ret += i + '0'; - } -} - -int main() -{ - std::cin >> s; - for(int i = 0; i < s.length(); i++) { - cnt[s[i]-'0']++; - } - std::cin >> t; - ret = ""; - for(int i = 0; i < t.length(); i++) { - cnt[t[i]-'0']--; - } - int tot = -1; - for(int i = 1; i <= 6; i++) { - int num = (int)s.length() - i; - int dig = 0; - for(;num;num/=10) dig++; - if(dig == i) { - tot = (int)s.length() - i; - break; - } - } - for(;tot;tot/=10) cnt[tot%10]--; - //前面不放 - ret += t; - for(int i = 0; i < 10; i++) - PushBackAll(i); - candidates.push_back(ret); - - ret = ""; - //前面要放,先确定首位的数字 - for(int i = 1; i < 10; i++) { - if(cnt[i]) { - ret += '0' + i; - cnt[i]--; - break; - } - } - std::string tmp = ret; - - //小于等于t[0]的数放前面 - for(int i = 0; i <= t[0]-'0'; i++) { - PushBackAll(i); - } - ret += t; - for(int i = t[0]-'0'+1; i < 10; i++) { - PushBackAll(i); - } - candidates.push_back(ret); - - //小于等于t[0]的数放后面 - ret = tmp; - for(int i = 0; i < t[0]-'0'; i++) { - PushBackAll(i); - } - ret += t; - for(int i = t[0]-'0'; i < 10; i++) { - PushBackAll(i); - } - candidates.push_back(ret); - - ret = ""; - for(auto it : candidates) { - if(it[0] != '0' || it.length() == 1) { - if(ret == "" || it < ret ) { - ret = it; - } - } - } - - std::cout << ret << std::endl; - return 0; -} diff --git a/wuyiqi/fzu2235.cpp b/wuyiqi/fzu2235.cpp deleted file mode 100644 index c8c16c38..00000000 --- a/wuyiqi/fzu2235.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include -#include -#include -#include -using namespace std; - -struct Point -{ - int x, y; - void print() { - printf("%d %d\n", x , y); - } - bool operator < (const Point &cmp) const { - return x < cmp.x || (x == cmp.x && y < cmp.y); - } - bool operator == (const Point &cmp) const { - return x == cmp.x && y == cmp.y; - } -}s, t; - -const int N = 100007; -const int M = 100010; -struct HashTable -{ - int head[N], nxt[M]; - Point pnt[M]; - int E; - void init() { - E = 0; - memset(head, -1, sizeof(head)); - } - void insert(Point p) { - long long h = (1LL * p.x * 1000007 + p.y) % N; - for(int i = head[h]; i != -1; i = nxt[i]) { - if(pnt[i] == p) { - return ; - } - } - pnt[E] = p; - nxt[E] = head[h]; - head[h] = E++; - } - int find(Point p) { - long long h = (1LL * p.x * 1000007 + p.y) % N; - for(int i = head[h]; i != -1; i = nxt[i]) { - if(pnt[i] == p) { - return i; - } - } - return -1; - } -}mp; - -int dx [] = {0, 1, 0, -1, 1, -1, -1, 1}; -int dy [] = {1, 0, -1, 0, 1, -1, 1, -1}; -int vis[M]; -Point Q[M]; -void bfs() -{ - int head = 0, tail = 0; - memset(vis, -1, sizeof(vis)); - Q[++tail] = s; - vis[mp.find(s)]=0; - while(head < tail) { - Point f = Q[++head]; - int fid = mp.find(f); - for(int i = 0; i < 8; i++) { - Point to; - to.x = f.x + dx[i]; - to.y = f.y + dy[i]; - int id = mp.find(to); - if(id != -1 && vis[id] == -1 ) { - Q[++tail] = to; - vis[id] = vis[fid] + 1; - if(to == t) { - printf("%d\n", vis[id]); - return ; - } - } - } - } - printf("-1\n"); -} -bool read (int &x) { - int c = getchar (); int sign = 1; - while (~c && c < '0' || c > '9') { if (c == '-') sign = -1; c = getchar (); } - for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar ()) x = x * 10 + c - '0'; - x *= sign; - return ~c; -} -int main() -{ - while(scanf("%d%d", &s.x, &s.y) == 2) { - mp.init(); - read(t.x); read(t.y); - mp.insert(s); - mp.insert(t); - int n; - scanf("%d", &n); - int r, a, b; - for(int i = 0; i < n; i++) { - read(r); read(a); read(b); - for(int j = a; j <= b; j++) { - Point tmp; - tmp.x = r; tmp.y = j; - mp.insert(tmp); - } - } - bfs(); - } - return 0; -} diff --git a/wuyiqi/lightoj/1006.cpp b/wuyiqi/lightoj/1006.cpp deleted file mode 100644 index 8070cd5c..00000000 --- a/wuyiqi/lightoj/1006.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -const int mod = 10000007; - -long long f[10010]; -int main() -{ - int T, ca = 1; - scanf("%d", &T); - while(T--) { - printf("Case %d: ", ca++); - int n; - for(int i = 0; i < 6; i++) { - scanf("%lld", &f[i]); - f[i] %= mod; - } - scanf("%d", &n); - for(int i = 6; i <= n; i++) { - f[i] = 0; - for(int j = i - 1; j >= i - 6; j--) { - f[i] += f[j]; - f[i] %= mod; - } - } - printf("%lld\n", f[n]); - } - return 0; -} diff --git a/wuyiqi/lightoj/lightoj_1001.cpp b/wuyiqi/lightoj/lightoj_1001.cpp deleted file mode 100644 index 6284d11c..00000000 --- a/wuyiqi/lightoj/lightoj_1001.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int main() { - int T, n; - scanf("%d", &T); - while(T--) { - scanf("%d", &n); - printf("%d %d\n", n/2, n-n/2); - } - return 0; -} \ No newline at end of file diff --git a/wuyiqi/lightoj/lightoj_1002.cpp b/wuyiqi/lightoj/lightoj_1002.cpp deleted file mode 100644 index a380cc63..00000000 --- a/wuyiqi/lightoj/lightoj_1002.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -using namespace std; -struct Edge -{ - int u, v, w; - void in() { - scanf("%d%d%d",&u, &v, &w); - } - bool operator < (const Edge& cmp) const { - return w < cmp.w; - } -}edge[16000]; -int fa[500]; - -int find(int x) -{ - return fa[x] == x ? x : fa[x] = find(fa[x]); -} - -int main() -{ - int T, ca = 1; - scanf("%d", &T); - while(T--) { - int n, m; - scanf("%d%d", &n, &m); - for(int i = 0; i < m; i++) { - edge[i].in(); - } - int t; - scanf("%d", &t); - sort(edge, edge + m); - for(int i = 0; i < n; i++) { - fa[i] = i; - } - int ret[500]; - memset(ret, -1, sizeof(ret)); - ret[t] = 0; - for(int i = 0; i < m; i++) { - int x = find(edge[i].u); - int y = find(edge[i].v); - if(x != y) { - fa[x] = y; - } - for(int j = 0; j < n; j++) if(ret[j]==-1) { - if(find(j) == find(t)) { - ret[j] = edge[i].w; - } - } - } - printf("Case %d:\n", ca++); - for(int i = 0; i < n; i++) { - if(ret[i] == -1) { - puts("Impossible"); - } else { - printf("%d\n", ret[i]); - } - } - } - return 0; -} \ No newline at end of file diff --git a/wuyiqi/lightoj/lightoj_1003.cpp b/wuyiqi/lightoj/lightoj_1003.cpp deleted file mode 100644 index 9f6e5457..00000000 --- a/wuyiqi/lightoj/lightoj_1003.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -map mp; -vector edge[100010]; -int vis[22222]; - -bool dfs(int u) -{ - vis[u] = 1; - for(int i = 0; i < edge[u].size(); i++) { - int v = edge[u][i]; - if(!vis[v]) { - if(!dfs(v)) - return false; - } else if(vis[v] == 1) { - return false; - } - } - vis[u] = 2; - return true; -} -int main() -{ - int T, ca = 1; - scanf("%d", &T); - while(T--) { - mp.clear(); - int n; - scanf("%d", &n); - char a[11], b[11]; - int tot = 0; - for(int i = 0; i < 20010; i++) edge[i].clear(); - for(int i = 0; i < n; i++) { - scanf("%s%s", a, b); - if(mp.find(a) == mp.end()) { - mp[a] = tot++; - } - if(mp.find(b) == mp.end()) { - mp[b] = tot++; - } - edge[mp[a]].push_back(mp[b]); - } - memset(vis, 0, sizeof(vis)); - bool flag = true; - for(int i = 0; i < tot; i++) if(!vis[i]){ - if(!dfs(i)) { - flag = false; - break; - } - } - printf("Case %d: ",ca ++); - if(flag) puts("Yes"); - else puts("No"); - } - return 0; -} diff --git a/wuyiqi/lightoj/lightoj_1116.cpp b/wuyiqi/lightoj/lightoj_1116.cpp deleted file mode 100644 index d6546999..00000000 --- a/wuyiqi/lightoj/lightoj_1116.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -using namespace std; - -#define LLD "%lld" -int main() -{ - int T, ca = 1; - scanf("%d", &T); - while(T--) { - long long W; - scanf(LLD, &W); - long long ret = 1; - while(W % 2 == 0) { - ret *= 2; - W /= 2; - } - printf("Case %d: ",ca++); - if(ret == 1 || W == 1) { - cout << "Impossible" << endl; - } else { - cout << W << " " << ret << endl; - } - } - return 0; -} diff --git "a/wuyiqi/\347\211\247\345\234\272\347\211\251\350\257\255.cpp" "b/wuyiqi/\347\211\247\345\234\272\347\211\251\350\257\255.cpp" deleted file mode 100644 index 75aedf8a..00000000 --- "a/wuyiqi/\347\211\247\345\234\272\347\211\251\350\257\255.cpp" +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -using namespace std; - -const int N = 111; -const long long INF = (long long) 1e14; -int a[N][N]; -long long dp[2 * N][N][N]; - -int dir[2][2] = {{1, 0}, {0, 1}}; -inline void Update(long long &x, long long y) -{ - if(y > x) { - x = y; - } -} -int n; -inline bool valid(int x, int y) -{ - return x >= 0 && x < n && y >= 0 && y < n; -} -int main() -{ - while(cin >> n) - { - - for(int i = 0; i < n; i++) { - for(int j = 0; j < n; j++) { - cin >> a[i][j]; - } - } - for(int i = 0; i < 2 * n; i++) { - for(int j = 0; j < n; j++) { - for(int k = 0; k < n; k++) { - dp[i][j][k] = -INF; - } - } - } - dp[0][0][0] = a[0][0]; - for(int i = 1; i <= 2*n-2; i++) { - for(int j = 0; j < n; j++) { - for(int k = 0; k < n; k++) if(dp[i - 1][j][k] != -INF){ - for(int d1 = 0; d1 < 2; d1++) { - for(int d2 = 0; d2 < 2; d2++) { - int x = j, y = i - 1 - j; - x += dir[d1][0]; y += dir[d1][1]; - int tx = k, ty = i - 1 - k; - tx += dir[d2][0]; ty += dir[d2][1]; - - if(valid(x, y) && valid(tx, ty)) { - if(x == tx && y == ty) { - Update(dp[i][x][tx], dp[i - 1][j][k] + a[x][y]); - } else { - Update(dp[i][x][tx], dp[i - 1][j][k] + a[x][y] + a[tx][ty]); - } - } - } - } - } - } - } - cout << dp[2 * n - 2][n - 1][n - 1] << endl; - } - return 0; -} diff --git a/xdlove/2016_05_05_51nod_1107.cpp b/xdlove/2016_05_05_51nod_1107.cpp deleted file mode 100644 index 339ddaa5..00000000 --- a/xdlove/2016_05_05_51nod_1107.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月05日 星期四 20时59分59秒 -File Name :2016_05_05_51nod_1391.cpp - ************************************************ */ - -//#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 5e4 + 5; -vector vec; -int c[N << 1]; - -struct Node -{ - int x,y; - void read() - { - scanf("%d %d",&x,&y); - } - void make_id() - { - x = get_id(x); - y = get_id(y); - } - int get_id(int x) - { - return lower_bound(vec.begin(),vec.end(),x) - vec.begin() + 1; - } - bool operator < (const Node &a) const - { - if(x != a.x) return x < a.x; - return y < a.y; - } -}p[N]; - -void add(int x,int n) -{ - while(x <= n) - { - c[x]++; - x += x & -x; - } -} - -int get_sum(int x,int n) -{ - int s = 0; - while(x > 0) - { - s += c[x]; - x -= x & -x; - } - return s; -} - -void solve() -{ - int n; - cin >> n; - for(int i = 0; i < n; ++i) - { - p[i].read(); - vec.push_back(p[i].x); - vec.push_back(p[i].y); - } - sort(vec.begin(),vec.end()); - vec.erase(unique(vec.begin(),vec.end()),vec.end()); - for(int i = 0; i < n; ++i) p[i].make_id(); - sort(p,p + n); - int ans = 0; - for(int i = 0; i < n; ++i) - { - int tp = get_sum(p[i].y,vec.size()); - ans += i - tp; - add(p[i].y,vec.size()); - } - cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/2016_05_06_51nod_1464.cpp b/xdlove/2016_05_06_51nod_1464.cpp deleted file mode 100644 index 1f4c81ac..00000000 --- a/xdlove/2016_05_06_51nod_1464.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月07日 星期六 15时49分30秒 -File Name :2016_05_06_51nod_1464.cpp - ************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 5005; -char s[N]; -int k,n,l,r; -bool dp[N][N]; -int vis[N]; -string ans; - -struct Tree -{ - Tree() - { - val = 0; - memset(next,0,sizeof next); - } - int val; - Tree *next[2]; -}*tree_head; - -void init() -{ - tree_head = new Tree(); - n = strlen(s); - memset(dp,false,sizeof dp); - for(int i = n - 1; i >= 0; --i) - { - dp[i][i] = true; - vis[i] = i; - for(int j = i + 1; j < n; ++j) - { - if(s[i] == s[j]) - { - if(i + 2 >= j - 2) - dp[i][j] = true; - else dp[i][j] = dp[i + 2][j - 2]; - } - if(dp[i][j]) vis[i] = j; - } - } -} - -void insert_tree(Tree *ptemp, char *s) -{ - if(*s == '\0') return; - if(r > vis[l]) return; - int c = *s - 'a'; - if(ptemp->next[c] == NULL) - ptemp->next[c] = new Tree(); - if(dp[l][r]) ptemp->next[c]->val++; - r++; - insert_tree(ptemp->next[c], s + 1); -} - -void dfs(Tree *ptemp) -{ - string temp = ans; - if(k > 0 && ptemp->next[0]) - { - k -= ptemp->next[0]->val; - ans = ans + 'a'; - dfs(ptemp->next[0]); - } - if(k > 0 && ptemp->next[1]) - { - ans = temp; - k -= ptemp->next[1]->val; - ans = ans + 'b'; - dfs(ptemp->next[1]); - } -} - -void solve() -{ - scanf("%s %d",s,&k); - init(); - for(int i = 0; i < n; ++i) - { - l = r = i; - insert_tree(tree_head,s + i); - } - dfs(tree_head); - cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/2016_05_06_51nod_1464.md b/xdlove/2016_05_06_51nod_1464.md deleted file mode 100644 index e08cae91..00000000 --- a/xdlove/2016_05_06_51nod_1464.md +++ /dev/null @@ -1,9 +0,0 @@ -题意: 求一个字符串的所有半回文串中,字典序第k小. - -题解: 字符串的最大长度可以达到5000,很明显O(n^2)的时间复杂度可以AC.那么我们可以先考虑O(n^2)预处理出所有的半回文串.我们假设DP[i] - -[j]=true表示子串s[i,j]是半回文子串,反之,不是半回文子串.那么可以得出dp[i+2][j-2]也是半回文串,所以可以得出状态转移方程dp[i][j]=dp - -[i+2][j-2]. 然后可以考虑以s[i]开头的所有半回文串,建一棵Trie,然后就可以通过DFS搜索出第k小的半回文子串.这部分的时间复杂度也为kO - -(n^2),所以总的算法时间复杂度为kO(n^2).k为字符串的字符种类. diff --git a/xdlove/2016_05_07_51nod_1127.cpp b/xdlove/2016_05_07_51nod_1127.cpp deleted file mode 100644 index e9541951..00000000 --- a/xdlove/2016_05_07_51nod_1127.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月07日 星期六 22时04分23秒 -File Name :2016_05_07_51nod_1127.cpp -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -int a[26]; - -void solve() -{ - string s; - int ans = 100006; - cin>>s; - int l = 0,cnt = 0; - for(int i = 0; i < s.length(); ++i) - { - if(a[s[i] - 'A'] == 0) cnt++; - a[s[i] - 'A']++; - while(cnt == 26) - { - ans = min(ans,i - l + 1); - a[s[l] - 'A']--; - if(a[s[l] - 'A'] == 0) - cnt--; - l++; - } - } - if(ans > 100000) - { - cout << "No Solution" << endl; - } - else cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/2016_05_08_51nod_1179.cpp b/xdlove/2016_05_08_51nod_1179.cpp deleted file mode 100644 index db0d602f..00000000 --- a/xdlove/2016_05_08_51nod_1179.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月09日 星期一 08时24分46秒 -File Name :2016_05_08_51nod_1179.cpp -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -const int N = 1e6 + 6; -int mp[N]; - -void solve() -{ - int n; - cin>>n; - memset(mp,0,sizeof(mp)); - for(int i = 0; i < n; ++i) - { - int x; - scanf("%d",&x); - mp[x] = 1; - } - int ans = 1; - for(int i = 2; i <= 1000000; ++i) - { - int cnt = 0; - for(int j = i; j <= 1000000; j += i) - { - if(mp[j]) cnt++; - } - if(cnt > 1) ans = i; - } - cout << ans << endl; -} - - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/2016_05_09_51nod_1335.cpp b/xdlove/2016_05_09_51nod_1335.cpp deleted file mode 100644 index 69046872..00000000 --- a/xdlove/2016_05_09_51nod_1335.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月09日 星期一 19时02分23秒 -File Name :2016_05_09_51nod_1335.cpp - ************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 3000; -string s; - -vector returnVec(vector &vec, int pos) -{ - vector ans; - int tp = pos; - for(int i = 0; i < vec.size(); ++i) - { - if(s[vec[i]] > s[pos]) continue; - if(s[vec[i]] < s[pos]) - { - pos = vec[i]; - ans.clear(); - } - if(tp != pos) ans.push_back(vec[i]); - } - return ans; -} - - -void solve() -{ - int T; - cin >> T; - while(T--) - { - cin >> s; - vector vec; - int l = 0; - while(true) - { - if(l >= s.length()) break; - for(int i = l + 1; i < s.length(); ++i) vec.push_back(i); - vec = returnVec(vec, l); - if(vec.size() > 0) break; - l++; - } - int r = 0; - if(vec.size() > 0) - { - string c = s; - for(int i = 0; i < vec.size(); ++i) - { - string tp = s; - reverse(tp.begin() + l,tp.begin() + vec[i] + 1); - if(tp < c) - { - r = vec[i]; - c = tp; - } - } - } - else l = 0; - printf("%d %d\n",l,r); - } -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git "a/xdlove/2016_\347\231\276\345\272\246\344\271\213\346\230\237/A.cpp" "b/xdlove/2016_\347\231\276\345\272\246\344\271\213\346\230\237/A.cpp" deleted file mode 100644 index a66ac4dc..00000000 --- "a/xdlove/2016_\347\231\276\345\272\246\344\271\213\346\230\237/A.cpp" +++ /dev/null @@ -1,93 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月14日 星期六 13时22分41秒 -File Name :A.cpp -************************************************ */ - -#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 1e5 + 10; -const int mod = 9973; -char s[N]; - -struct Stree -{ - int val[N << 2]; - void pushup(int u) - { - val[u] = val[u << 1] * val[u << 1 | 1] % mod; - } - void build(int u,int l,int r) - { - if(l == r) - { - val[u] = (s[l] - 28 + mod) % mod; - } - else - { - int mid = l + (r - l) / 2; - build(u << 1,l,mid); - build(u << 1 | 1,mid + 1,r); - pushup(u); - } - } - int query(int u,int l,int r,int x,int y) - { - if(x <= l && y >= r) - return val[u]; - else - { - int mid = (r - l) / 2 + l; - int res = 1; - if(x <= mid) res = res * query(u << 1,l,mid,x,y) % mod; - if(y > mid) res = res * query(u << 1 | 1,mid + 1,r,x,y) % mod; - return res; - } - } -}tree; - -void solve() -{ - int n,l,r,tp = 0; - while(~scanf("%d",&n)) - { - getchar(); - gets(s + 1); - int len = strlen(s + 1); - tree.build(1,1,len); - while(n--) - { - scanf("%d %d",&l,&r); - if(l > r) swap(l,r); - if(l < 1 || r < 1 || l > len || r > len) - { - printf("%d\n",tp); - continue; - } - tp = tree.query(1,1,len,l,r); - printf("%d\n",tp); - } - } -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git "a/xdlove/2016_\347\231\276\345\272\246\344\271\213\346\230\237/D.cpp" "b/xdlove/2016_\347\231\276\345\272\246\344\271\213\346\230\237/D.cpp" deleted file mode 100644 index 07dfa149..00000000 --- "a/xdlove/2016_\347\231\276\345\272\246\344\271\213\346\230\237/D.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月14日 星期六 13时12分41秒 -File Name :D.cpp -************************************************ */ - -#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -mapmp; -char s[50]; - -void solve() -{ - int N; - cin >> N; - for(int i = 0; i < N; ++i) - { - scanf("%s",s); - sort(s,s + strlen(s)); - int ans = mp[s]; - printf("%d\n",ans); - mp[s]++; - } -} - - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/51nod/2016_05_05_51nod_1107.cpp b/xdlove/51nod/2016_05_05_51nod_1107.cpp deleted file mode 100644 index 339ddaa5..00000000 --- a/xdlove/51nod/2016_05_05_51nod_1107.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月05日 星期四 20时59分59秒 -File Name :2016_05_05_51nod_1391.cpp - ************************************************ */ - -//#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 5e4 + 5; -vector vec; -int c[N << 1]; - -struct Node -{ - int x,y; - void read() - { - scanf("%d %d",&x,&y); - } - void make_id() - { - x = get_id(x); - y = get_id(y); - } - int get_id(int x) - { - return lower_bound(vec.begin(),vec.end(),x) - vec.begin() + 1; - } - bool operator < (const Node &a) const - { - if(x != a.x) return x < a.x; - return y < a.y; - } -}p[N]; - -void add(int x,int n) -{ - while(x <= n) - { - c[x]++; - x += x & -x; - } -} - -int get_sum(int x,int n) -{ - int s = 0; - while(x > 0) - { - s += c[x]; - x -= x & -x; - } - return s; -} - -void solve() -{ - int n; - cin >> n; - for(int i = 0; i < n; ++i) - { - p[i].read(); - vec.push_back(p[i].x); - vec.push_back(p[i].y); - } - sort(vec.begin(),vec.end()); - vec.erase(unique(vec.begin(),vec.end()),vec.end()); - for(int i = 0; i < n; ++i) p[i].make_id(); - sort(p,p + n); - int ans = 0; - for(int i = 0; i < n; ++i) - { - int tp = get_sum(p[i].y,vec.size()); - ans += i - tp; - add(p[i].y,vec.size()); - } - cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/51nod/2016_05_06_51nod_1464.cpp b/xdlove/51nod/2016_05_06_51nod_1464.cpp deleted file mode 100644 index 1f4c81ac..00000000 --- a/xdlove/51nod/2016_05_06_51nod_1464.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月07日 星期六 15时49分30秒 -File Name :2016_05_06_51nod_1464.cpp - ************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 5005; -char s[N]; -int k,n,l,r; -bool dp[N][N]; -int vis[N]; -string ans; - -struct Tree -{ - Tree() - { - val = 0; - memset(next,0,sizeof next); - } - int val; - Tree *next[2]; -}*tree_head; - -void init() -{ - tree_head = new Tree(); - n = strlen(s); - memset(dp,false,sizeof dp); - for(int i = n - 1; i >= 0; --i) - { - dp[i][i] = true; - vis[i] = i; - for(int j = i + 1; j < n; ++j) - { - if(s[i] == s[j]) - { - if(i + 2 >= j - 2) - dp[i][j] = true; - else dp[i][j] = dp[i + 2][j - 2]; - } - if(dp[i][j]) vis[i] = j; - } - } -} - -void insert_tree(Tree *ptemp, char *s) -{ - if(*s == '\0') return; - if(r > vis[l]) return; - int c = *s - 'a'; - if(ptemp->next[c] == NULL) - ptemp->next[c] = new Tree(); - if(dp[l][r]) ptemp->next[c]->val++; - r++; - insert_tree(ptemp->next[c], s + 1); -} - -void dfs(Tree *ptemp) -{ - string temp = ans; - if(k > 0 && ptemp->next[0]) - { - k -= ptemp->next[0]->val; - ans = ans + 'a'; - dfs(ptemp->next[0]); - } - if(k > 0 && ptemp->next[1]) - { - ans = temp; - k -= ptemp->next[1]->val; - ans = ans + 'b'; - dfs(ptemp->next[1]); - } -} - -void solve() -{ - scanf("%s %d",s,&k); - init(); - for(int i = 0; i < n; ++i) - { - l = r = i; - insert_tree(tree_head,s + i); - } - dfs(tree_head); - cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/51nod/2016_05_06_51nod_1464.md b/xdlove/51nod/2016_05_06_51nod_1464.md deleted file mode 100644 index e08cae91..00000000 --- a/xdlove/51nod/2016_05_06_51nod_1464.md +++ /dev/null @@ -1,9 +0,0 @@ -题意: 求一个字符串的所有半回文串中,字典序第k小. - -题解: 字符串的最大长度可以达到5000,很明显O(n^2)的时间复杂度可以AC.那么我们可以先考虑O(n^2)预处理出所有的半回文串.我们假设DP[i] - -[j]=true表示子串s[i,j]是半回文子串,反之,不是半回文子串.那么可以得出dp[i+2][j-2]也是半回文串,所以可以得出状态转移方程dp[i][j]=dp - -[i+2][j-2]. 然后可以考虑以s[i]开头的所有半回文串,建一棵Trie,然后就可以通过DFS搜索出第k小的半回文子串.这部分的时间复杂度也为kO - -(n^2),所以总的算法时间复杂度为kO(n^2).k为字符串的字符种类. diff --git a/xdlove/51nod/2016_05_07_51nod_1127.cpp b/xdlove/51nod/2016_05_07_51nod_1127.cpp deleted file mode 100644 index e9541951..00000000 --- a/xdlove/51nod/2016_05_07_51nod_1127.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月07日 星期六 22时04分23秒 -File Name :2016_05_07_51nod_1127.cpp -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -int a[26]; - -void solve() -{ - string s; - int ans = 100006; - cin>>s; - int l = 0,cnt = 0; - for(int i = 0; i < s.length(); ++i) - { - if(a[s[i] - 'A'] == 0) cnt++; - a[s[i] - 'A']++; - while(cnt == 26) - { - ans = min(ans,i - l + 1); - a[s[l] - 'A']--; - if(a[s[l] - 'A'] == 0) - cnt--; - l++; - } - } - if(ans > 100000) - { - cout << "No Solution" << endl; - } - else cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/51nod/2016_05_08_51nod_1179.cpp b/xdlove/51nod/2016_05_08_51nod_1179.cpp deleted file mode 100644 index db0d602f..00000000 --- a/xdlove/51nod/2016_05_08_51nod_1179.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月09日 星期一 08时24分46秒 -File Name :2016_05_08_51nod_1179.cpp -************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -const int N = 1e6 + 6; -int mp[N]; - -void solve() -{ - int n; - cin>>n; - memset(mp,0,sizeof(mp)); - for(int i = 0; i < n; ++i) - { - int x; - scanf("%d",&x); - mp[x] = 1; - } - int ans = 1; - for(int i = 2; i <= 1000000; ++i) - { - int cnt = 0; - for(int j = i; j <= 1000000; j += i) - { - if(mp[j]) cnt++; - } - if(cnt > 1) ans = i; - } - cout << ans << endl; -} - - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/51nod/2016_05_09_51nod_1335.cpp b/xdlove/51nod/2016_05_09_51nod_1335.cpp deleted file mode 100644 index 69046872..00000000 --- a/xdlove/51nod/2016_05_09_51nod_1335.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月09日 星期一 19时02分23秒 -File Name :2016_05_09_51nod_1335.cpp - ************************************************ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -const int N = 3000; -string s; - -vector returnVec(vector &vec, int pos) -{ - vector ans; - int tp = pos; - for(int i = 0; i < vec.size(); ++i) - { - if(s[vec[i]] > s[pos]) continue; - if(s[vec[i]] < s[pos]) - { - pos = vec[i]; - ans.clear(); - } - if(tp != pos) ans.push_back(vec[i]); - } - return ans; -} - - -void solve() -{ - int T; - cin >> T; - while(T--) - { - cin >> s; - vector vec; - int l = 0; - while(true) - { - if(l >= s.length()) break; - for(int i = l + 1; i < s.length(); ++i) vec.push_back(i); - vec = returnVec(vec, l); - if(vec.size() > 0) break; - l++; - } - int r = 0; - if(vec.size() > 0) - { - string c = s; - for(int i = 0; i < vec.size(); ++i) - { - string tp = s; - reverse(tp.begin() + l,tp.begin() + vec[i] + 1); - if(tp < c) - { - r = vec[i]; - c = tp; - } - } - } - else l = 0; - printf("%d %d\n",l,r); - } -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/51nod/2016_05_14_51nod_1670.cpp b/xdlove/51nod/2016_05_14_51nod_1670.cpp deleted file mode 100644 index 2f5df5df..00000000 --- a/xdlove/51nod/2016_05_14_51nod_1670.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月14日 星期六 07时52分21秒 -File Name :2016_05_14_51nod_1670.cpp -************************************************ */ - -//#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -const int N = 1e5 + 5; -typedef long long ll; -const int mod = 1e9 + 7; -int mp[N],fact[N]; - -void Fact(int n) -{ - fact[0] = fact[1] = 1; - for(int i = 2; i <= n; ++i) - fact[i] = 1LL * fact[i - 1] * i % mod; -} - -void solve() -{ - memset(mp, 0, sizeof mp); - int n,i; - cin >> n; - Fact(n); - for(i = 1; i <= n; ++i) - { - int x; - scanf("%d",&x); - mp[x]++; - } - ll ans = 0,tp = 1; - int num = 0; - for(i = 0; i < n; ++i) - { - num += mp[i]; - if(num - i == 0) break; - if(n - num) - { - ans = (ans + tp * (n - num) % mod * fact[n - i - 1] % mod * i % mod) % mod; - } - tp = tp * (num - i) % mod; - } - if(num - i + 1 > 0) - { - ans = (ans + tp * i % mod * fact[n - i] % mod) % mod; - } - cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/CF352/2016_05_12_A.cpp b/xdlove/CF352/2016_05_12_A.cpp deleted file mode 100644 index 3d955b17..00000000 --- a/xdlove/CF352/2016_05_12_A.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月12日 星期四 08时14分28秒 -File Name :CF352/2016_05_12_A.cpp -************************************************ */ - -#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -void solve() -{ - int n; - string s; - cin >> n; - for(int i = 1; i <= 1000; ++i) - { - s += to_string(i); - } - cout << s[n - 1] << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/CF352/2016_05_12_B.cpp b/xdlove/CF352/2016_05_12_B.cpp deleted file mode 100644 index 68cb4d53..00000000 --- a/xdlove/CF352/2016_05_12_B.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月12日 星期四 08时21分19秒 -File Name :CF352/2016_05_12_B.cpp -************************************************ */ - -#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -void solve() -{ - int n,ans; - string s; - cin >> n >> s; - map mp; - ans = s.length(); - if(ans > 26) ans = -1; - else - for(int i = 0; i < n; ++i) - { - if(mp[s[i]] == 0) - { - --ans; - mp[s[i]] = 1; - } - } - cout << ans << endl; -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/LightOj/2016_05_10_1213_Fantasy_of_a_Summation.cpp b/xdlove/LightOj/2016_05_10_1213_Fantasy_of_a_Summation.cpp deleted file mode 100644 index 76e37ef6..00000000 --- a/xdlove/LightOj/2016_05_10_1213_Fantasy_of_a_Summation.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* *********************************************** -Author :xdlove -Created Time :2016年05月10日 星期二 20时27分30秒 -File Name :2016_05_10_1213_Fantasy_of_a_Summation.cpp -************************************************ */ - -#pragma comment(linker, "/STACK:1024000000,1024000000") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -int Pow(int n,int k,int mod) -{ - int res = 1; - while(k) - { - if(k & 1) res = 1LL * res * n % mod; - n = 1LL * n * n % mod; - k >>= 1; - } - return res; -} - -void solve() -{ - int T,n,k,mod; - int cnt = 1; - cin >> T; - while(T--) - { - scanf("%d %d %d",&n,&k,&mod); - int ans = Pow(n,k - 1,mod); - int sum = 0,x; - for(int i = 0; i < n; ++i) - { - scanf("%d",&x); - sum = (0LL + sum + x) % mod; - } - ans = 1LL * ans * sum % mod; - ans = 1LL * ans * k % mod; - printf("Case %d: %d\n",cnt++,ans); - } -} - -int main() -{ - //freopen("in.txt","r",stdin); - //freopen("out.txt","w",stdout); - solve(); - return 0; -} diff --git a/xdlove/README.md b/xdlove/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/yunmagz/2016_05_05.cpp b/yunmagz/2016_05_05.cpp deleted file mode 100644 index 0ffde301..00000000 --- a/yunmagz/2016_05_05.cpp +++ /dev/null @@ -1,31 +0,0 @@ -//lightoj1119 - Pimp My Ride -#include -using namespace std; -const int INF = 0x3f3f3f3f; -int dp[(1<<14)+10],mp[15][15]; -int main() -{ - int t,cas=1,n; - cin>>t; - while(t--){ - cin>>n; - memset(dp,INF,sizeof dp); - for(int i=0;i>mp[i][j]; - dp[0]=0; - for(int i=0;i<(1< -#define LL long long -using namespace std; -char s[500010],t[500010]; -int n, m, now; -int stk[500010],top,h[500010]; -int pre[500010],nxt[500010]; -int main(){ - cin >> n >> m >> now; - scanf("%s%s", s + 1,t+1); - for(int i = 1; i <= n; i ++){ - nxt[i] = i + 1; - pre[i] = i - 1; - } - nxt[0] = 1; - pre[n + 1] = 0; - for(int i = 1; i <= n; i++){ - if(s[i]=='(')stk[++top]=i; - else h[i]=stk[top--],h[h[i]]=i; - } - for(int T = 1; T <= m; T ++){ - if(t[T]=='L')now=pre[now]; - if(t[T]=='R')now=nxt[now]; - if(t[T]=='D'){ - int x=now,y=h[now]; - if(x>y)swap(x,y); - x=pre[x],y=nxt[y]; - nxt[x]=y,pre[y]=x; - now=y; - } - if(now==n+1)now=pre[n+1]; - } - for(int i=nxt[0];i<=n;i=nxt[i])putchar(s[i]); -} diff --git a/yunmagz/2016_05_07.cpp b/yunmagz/2016_05_07.cpp deleted file mode 100644 index 7509cb2f..00000000 --- a/yunmagz/2016_05_07.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -using namespace std; -#define LL long long -#define ULL unsigned long long -const int MAXN = 200000; -const int mod = 1e9+7; -int bit[50]; -LL dp[40][2][40][40]; -int m,n; -LL dfs(int cur,int e,int get0,bool flag) -{ - if(cur==-1)return get0==0; - if(!flag&&~dp[cur][e][get0][m])return dp[cur][e][get0][m]; - LL ans=0; - int end=flag?bit[cur]:1; - for(int i=0;i<=end;i++) - if(get0>=(i&&e)) - ans+=dfs(cur-1,i,get0-(i&&e),flag&&i==end); - if(!flag) - dp[cur][e][get0][m]=ans; - return ans; -} -LL cal(int n) -{ - int cnt=0; - while(n) - { - bit[cnt++]=n&1; - n>>=1; - } - LL ans=0; - for(int i=1;i<=32;i++) - { - m=i; - ans+=dfs(cnt-1,0,i,1)*i; - } - return ans; -} -int main() -{ - int t,cas=1; - cin>>t; - memset(dp,-1,sizeof dp); - while(t--) - { - cin>>n; - printf("Case %d: %lld\n",cas++,cal(n)); - } - return 0; -} diff --git a/yunmagz/2016_05_08.cpp b/yunmagz/2016_05_08.cpp deleted file mode 100644 index add55111..00000000 --- a/yunmagz/2016_05_08.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//GCJ2016 1C A-Senate Evacuation -#include -using namespace std; -int a[30]; -int main() -{ -// freopen("in.in","r",stdin); -// freopen("out.out","w",stdout); - int t,n,cas=1; - cin>>t; - while(t--){ - cin>>n; - for(int i=0;i>a[i]; - printf("Case #%d:",cas++); - while(1){ - vectorv; - int mx=0; - for(int i=0;i -using namespace std; -long long n,m; -long long er[55]; -int mp[55][55],cas=1; -int main() -{ -// freopen("in.in","r",stdin); -// freopen("out.out","w",stdout); - int t; - cin>>t; - er[0]=1; - er[1]=1; - for(int i=2;i<=50;i++) er[i]=er[i-1]*2; - while(t--){ - cin>>n>>m; - printf("Case #%d:",cas++); - memset(mp,0,sizeof mp); - for(int i=0;i=0;i--){ - if(m>=er[i]){ - m-=er[i]; - mp[i][n-1]=1; - } - } - if(m)puts(" IMPOSSIBLE"); - else { - puts(" POSSIBLE"); - for(int i=0;i -using namespace std; -int main() -{ -// freopen("in.in","r",stdin); -// freopen("out.out","w",stdout); - int t,cas=1,j,p,s,k; - cin>>t; - while(t--){ - cin>>j>>p>>s>>k; - printf("Case #%d: ",cas++); - if(k>s){ - printf("%d\n",j*p*s); - for(int i=0;i -using namespace std; -#define LL long long -const int mod=1e8+7; -LL dp[2][15010]; -int main() -{ -// freopen("in.in","r",stdin); -// freopen("out.out","w",stdout); - int t,cas=1,n,s,k; - cin>>t; - while(t--){ - cin>>n>>k>>s; - memset(dp,0,sizeof dp); - dp[0][0]=1; - LL sum=0; - int now=0; - for(int i=1;i<=n;i++){ - sum=0; - now^=1; - for(int j=0;j<=s;j++){ - if(j) sum=(sum+dp[now^1][j-1])%mod; - if(j>k) sum=((sum-dp[now^1][j-k-1])%mod+mod)%mod; - dp[now][j]=sum; - } - } - printf("Case %d: %d\n",cas++,dp[now][s]); - } - return 0; -} diff --git a/yunmagz/2016_05_10.cpp b/yunmagz/2016_05_10.cpp deleted file mode 100644 index 694c3534..00000000 --- a/yunmagz/2016_05_10.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//lightoj 1191-Bar Codes -#include -using namespace std; -#define LL long long -int n,k,m; -LL dp[55],A[55]; -int main(){ - int cas=1,t; - cin>>t; - while(t--){ - scanf("%d%d%d",&n,&k,&m); - memset(dp,0,sizeof dp); - memset(A,0,sizeof A); - dp[0]=1; - int l,r; - LL sum=0; - for(int i=1;i<=k;i++){ - for(int j=0;j<=n;j++){ - l=j+1,r=min(j+m+1,n+1); - A[l]+=dp[j]; - A[r]-=dp[j]; - } - sum=0; - for(int j=0;j<=n;j++){ - sum+=A[j]; - dp[j]=sum; - A[j]=0; - } - } - printf("Case %d: %lld\n",cas++,dp[n]); - } - return 0; -} diff --git a/yunmagz/2016_05_11.cpp b/yunmagz/2016_05_11.cpp deleted file mode 100644 index fe50ea81..00000000 --- a/yunmagz/2016_05_11.cpp +++ /dev/null @@ -1,31 +0,0 @@ -//lightoj 1193 - Dice (II) -//前缀和推得快吐了!!! -#include -using namespace std; -#define LL long long -const int mod=1e8+7; -LL dp[2][15010],sum[15010]; -int main() -{ -// freopen("in.in","r",stdin); -// freopen("out.out","w",stdout); - int t,cas=1,n,s,k; - cin>>t; - while(t--){ - scanf("%d%d%d",&n,&k,&s); - memset(dp,0,sizeof dp); - for(int i=1;i<=s;i++) - dp[0][i]=dp[0][i-1]+(i<=k?i:0); - int now=0; - for(int i=2;i<=n;i++){ - now^=1; - for(int j=1;j<=s;j++){ - if(j<=k) dp[now][j]=(dp[now][j-1]+sum[j-1])%mod; - else dp[now][j]=((dp[now][j-1]+sum[j-1]-sum[j-k-1]-dp[now^1][j-k-1]*k)%mod+mod)%mod; - sum[j]=(sum[j-1]+dp[now^1][j])%mod; - } - } - printf("Case %d: %d\n",cas++,((dp[now][s]-dp[now][s-1])%mod+mod)%mod); - } - return 0; -} diff --git a/yunmagz/2016_05_12.cpp b/yunmagz/2016_05_12.cpp deleted file mode 100644 index 767c5fd6..00000000 --- a/yunmagz/2016_05_12.cpp +++ /dev/null @@ -1,76 +0,0 @@ -//lightoj 1051 - Good or Bad -#include -using namespace std; -#define LL long long -char s[55]; -int v[55]; -bool dp[55][2]; -bool ok(char a){ - if(a=='A'||a=='E'||a=='I'||a=='O'||a=='U') - return 1; - else - return 0; -} -bool jg1(int x){ - if(x<3) return false; - for(int i=0;i<3;i++) if(v[x-i]>0) return false; - return true; -} -bool jg2(int x){ - if(x<5) return false; - for(int i=0;i<5;i++) if(v[x-i]<0) return false; - return true; -} - -int main() -{ -// freopen("in.in","r",stdin); -// freopen("out.out","w",stdout); - int t,cas=1; - cin>>t; - while(t--){ - scanf("%s",s); - printf("Case %d: ",cas++); - int n=strlen(s); - for(int i=0;i=0) dp[i][1]=1; - } - else { - if(v[i]<=0){ - if(v[i-1]>=0) dp[i][0]=(dp[i-1][1]||dp[i][0]); - if(v[i-1]<=0&&v[i-2]>=0) dp[i][0]=(dp[i-2][1]||dp[i][0]); - } - if(v[i]>=0){ - if(v[i-1]<=0) dp[i][1]=(dp[i][1]||dp[i-1][0]); - if(v[i-1]>=0){ - if(v[i-2]<=0) dp[i][1]=(dp[i][1]||dp[i-2][0]); - if(v[i-2]>=0){ - if(v[i-3]<=0) dp[i][1]=(dp[i][1]||dp[i-3][0]); - if(v[i-3]>=0) { - if(v[i-4]<=0) dp[i][1]=(dp[i][1]||dp[i-4][0]); - } - } - } - } - } - } - if(dp[n][0]||dp[n][1]) puts("MIXED"); - else puts("BAD"); - } - } - return 0; -} diff --git a/yunmagz/2016_05_13.cpp b/yunmagz/2016_05_13.cpp deleted file mode 100644 index 52ca91f5..00000000 --- a/yunmagz/2016_05_13.cpp +++ /dev/null @@ -1,49 +0,0 @@ -//lightoj 1057 - Collecting Gold -#include -using namespace std; -const int inf = 0x3f3f3f3f; -int dp[(1<<16)+10][16]; -int x[20],y[20]; -char mp[25][25]; -int dis(int i,int j){ - return max(abs(x[i]-x[j]),abs(y[i]-y[j])); -} -int main(){ - int cas=1,t,n,m; - scanf("%d",&t); - while(t--){ - int cnt=0; - scanf("%d%d",&n,&m); - for(int i=0;i +#include +#include +using namespace std; + +int is_prime[40]; +int loop[25]; +int vis[25]; +int cnt,n; + +void init() +{ + memset(is_prime,0,sizeof(is_prime)); + memset(loop,0,sizeof(loop)); + memset(vis,0,sizeof(vis)); + + loop[1]=1; + vis[1]=1; + + for(int i=2;i<=40;i++) + { + int flag=0; + for(int j=2;j*j<=i;j++) + { + if(i%j==0) + { + flag=1; + break; + } + } + if(flag==0) + { + is_prime[i]=1; + } + } +} + +void output() +{ + cout<>n) + { + init(); + printf("Case %d:\n",z++); + dfs(2); + cout< +#include +using namespace std; +int main() +{ + long long t,n; + double x,ans; + cin>>t; + while(t--) + { + cin>>n; + x=n*log10(n); + ans=pow(10,x-(long long)x); + cout<<(int)ans<