delete pics to save space

This commit is contained in:
2023-08-03 09:22:52 +08:00
commit de60cd6ed4
1334 changed files with 66221 additions and 0 deletions

0
.nojekyll Normal file
View File

27
1.1000.cpp Normal file
View File

@ -0,0 +1,27 @@
#include<cstdio>
int main()
{
printf(" ********\n");
printf(" ************\n");
printf(" ####....#.\n");
printf(" #..###.....##....\n");
printf(" ###.......###### ### ###\n");
printf(" ........... #...# #...#\n");
printf(" ##*####### #.#.# #.#.#\n");
printf(" ####*******###### #.#.# #.#.#\n");
printf(" ...#***.****.*###.... #...# #...#\n");
printf(" ....**********##..... ### ###\n");
printf(" ....**** *****....\n");
printf(" #### ####\n");
printf(" ###### ######\n");
printf("##############################################################\n");
printf("#...#......#.##...#......#.##...#......#.##------------------#\n");
printf("###########################################------------------#\n");
printf("#..#....#....##..#....#....##..#....#....#####################\n");
printf("########################################## #----------#\n");
printf("#.....#......##.....#......##.....#......# #----------#\n");
printf("########################################## #----------#\n");
printf("#.#..#....#..##.#..#....#..##.#..#....#..# #----------#\n");
printf("########################################## ############\n");
return 0;
}

8
1.1001.cpp Normal file
View File

@ -0,0 +1,8 @@
#include<cstdio>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
return 0;
}

43
1.1005.cpp Normal file
View File

@ -0,0 +1,43 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int128 LLL;
const int maxn=81;
int n,m;
int a[maxn];
LLL res,p[maxn],val[maxn][maxn];
bool vis[maxn][maxn];
LLL dp(int L,int R)
{
LLL &res=val[L][R];
if(vis[L][R]) return res;
int k=m-(R-L); vis[L][R]=true;
if(R-L+1>=2) res=max(a[L]*p[k]+dp(L+1,R),dp(L,R-1)+a[R]*p[k]);
else res=a[L]*p[k];
return res;
}
void print(LLL x)
{
if(!x) return;
print(x/10);
putchar(x%10+'0');
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
p[0]=1;
for(int i=1;i<=m;i++) p[i]=p[i-1]*2;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) scanf("%d",&a[j]);
memset(vis,0,sizeof(vis));
res+=dp(1,m);
}
if(!res) puts("0");
else print(res),puts("");
return 0;
}

28
1.1006.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<cstdio>
#include<cstring>
const int maxn=55;
int n,m,a[maxn][maxn],dp[2*maxn][maxn][maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
memset(dp,-1,sizeof(dp));
dp[2][1][1]=0;
for(int k=3;k<=n+m-1;k++)
for(int x1=1;x1<m;x1++)
for(int x2=x1+1;x2<=m;x2++)
{
int s=dp[k][x1][x2];
if(dp[k-1][x1][x2]>s) s=dp[k-1][x1][x2];
if(dp[k-1][x1][x2-1]>s) s=dp[k-1][x1][x2-1];
if(dp[k-1][x1-1][x2]>s) s=dp[k-1][x1-1][x2];
if(dp[k-1][x1-1][x2-1]>s) s=dp[k-1][x1-1][x2-1];
if(s==-1) continue;
dp[k][x1][x2]=s+a[k-x1][x1]+a[k-x2][x2];
}
printf("%d\n",dp[m+n-1][m-1][m]);
return 0;
}

16
1.1007.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int n,l,p,maxv,minv;
int main()
{
scanf("%d%d",&l,&n);
for(int i=0;i<n;i++)
{
scanf("%d",&p);
maxv=max(maxv,max(l-p+1,p));
minv=max(minv,min(l-p+1,p));
}
printf("%d %d",minv,maxv);
return 0;
}

17
1.1008.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int res[]={1,2,3,4,5,6,7,8,9};
int main()
{
int a,b,c;
do
{
a=res[0]*100+res[1]*10+res[2];
b=res[3]*100+res[4]*10+res[5];
c=res[6]*100+res[7]*10+res[8];
if(a*6==b*3&&b*3==c*2) printf("%d %d %d\n",a,b,c);
}
while(next_permutation(res,res+9));
return 0;
}

124
1.1009.cpp Normal file
View File

@ -0,0 +1,124 @@
// luogu-judger-enable-o2
#include<vector>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
int CacheSize=10;//try to use the cache
struct BigInt
{
bool f;
std::vector<int> num;
static const int base=100000000;
BigInt()
{
f=0;
num.push_back(0);
}
void format()
{
while(num.size()>1&&num[num.size()-1]==0) num.erase(num.end()-1);
if(num.size()==1&&num[0]==0) f=0;
}
//Input and Output
char* c_str()
{
char *p;
p=new char[num.size()*8+16];
memset(p,0,sizeof(p));
if(f) sprintf(p,"-");
sprintf(p,"%s%d",p,num[num.size()-1]);
for(int i=num.size()-2;i>=0;i--) sprintf(p,"%s%08d",p,num[i]);
return p;
}
BigInt operator=(int v)
{
f=0;
if(v<0)
{
f=1;
v=-v;
}
std::queue<int> q;
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator+(BigInt& b)
{
format();
b.format();
BigInt c;
int t=0,t2=std::max(num.size(),b.num.size())+1;
c.num.resize(t2);
memset(&c.num[0],0,t2*4);
for(int i=0;i<t2;i++)
{
if(i<num.size()) t+=num[i];
if(i<b.num.size()) t+=b.num[i];
c.num[i]=t%base;
t/=base;
}
c.format();
return c;
}
BigInt operator*(BigInt& b)
{
format();
b.format();
BigInt c;
c.num.resize(num.size()+b.num.size());
memset(&c.num[0],0,(num.size()+b.num.size())*4);
int i,j,k,I,J;
long long t;
for(i=0;i*CacheSize<num.size();i++)
for(j=0;j*CacheSize<b.num.size();j++)
for(I=i*CacheSize;I<(i+1)*CacheSize&&I<num.size();I++)
for(J=j*CacheSize;J<(j+1)*CacheSize&&J<b.num.size();J++)
{
t=(long long)num[I]*b.num[J];
t+=c.num[I+J];
c.num[I+J]=t%base;
k=I+J+1;
t/=base;
while(t>0)
{
t+=c.num[k];
c.num[k++]=t%base;
t/=base;
}
}
c.f=(f!=b.f);
c.format();
return c;
}
};
using namespace std;
int main()
{
BigInt res,t,t2;
t=1;
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
t2=i;
t=t*t2;
res=res+t;
}
printf("%s\n",res.c_str());
return 0;
}

26
1.1010.cpp Normal file
View File

@ -0,0 +1,26 @@
#include<cstdio>
int f(int x)
{
if(x==0) return printf("0");
bool flag=false;
for(int i=30;i>=0;i--)
if(x&(1<<i))
{
if(flag) printf("+");
flag=true;
if(i==1) printf("2");
else
{
printf("2(");
f(i);
printf(")");
}
}
}
int main()
{
int n;
scanf("%d",&n);
f(n);
return 0;
}

18
1.1014.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<cstdio>
typedef long long LL;
int main()
{
LL L=1,R,M,n,a;
scanf("%lld",&n);
R=n;
while(L<R)
{
M=(L+R)/2;
if(M*(M+1)/2<n) L=M+1;
else R=M;
}
a=n-L*(L-1)/2;
if(L%2==0) printf("%lld/%lld\n",a,L+1-a);
else printf("%lld/%lld\n",L+1-a,a);
return 0;
}

1178
1.1018.cpp Normal file

File diff suppressed because it is too large Load Diff

18
1.1024.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<cstdio>
#include<cmath>
int main()
{
double a,b,c,d;
double as,bs,t,si;
double x1,x2,x3;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
as=b*b-3*a*c;
bs=b*c-9*a*d;
t=(2*as*b-3*a*bs)/(2*sqrt(as*as*as));
si=acos(t);
x1=(-b-2*sqrt(as)*cos(si/3))/(3*a);
x2=(-b+sqrt(as)*(cos(si/3)+sqrt(3)*sin(si/3)))/(3*a);
x3=(-b+sqrt(as)*(cos(si/3)-sqrt(3)*sin(si/3)))/(3*a);
printf("%.2lf %.2lf %.2lf\n",x1,x3,x2);
return 0;
}

34
1.1026.cpp Normal file
View File

@ -0,0 +1,34 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[205],word[7][205];
int p,k,n,len_s;
int hav[205][205],len[205],dp[205][45];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&p,&k);
for(int i=0;i<p;i++) scanf("%s",s+i*20); len_s=strlen(s);
scanf("%d",&n);
for(int i=0;i<n;i++) { scanf("%s",word[i]); len[i]=strlen(word[i]); }
for(int r=0;r<len_s;r++)
for(int l=r;l>=0;l--)
{
hav[l][r]=hav[l+1][r];
for(int i=0;i<n;i++)
{
char* p=strstr(s+l,word[i]);
if(p!=NULL&&p==s+l&&len[i]<=r-l+1) { hav[l][r]++; break; }
}
}
for(int i=0;i<len_s;i++) dp[i][1]=hav[0][i];
for(int i=2;i<=k;i++)
for(int j=0;j<len_s;j++)
for(int l=j-1;l>=i-1;l--)
dp[j][i]=max(dp[j][i],dp[l-1][i-1]+hav[l][j]);
printf("%d\n",dp[len_s-1][k]);
return 0;
}

12
1.1028.cpp Normal file
View File

@ -0,0 +1,12 @@
#include<cstdio>
int n,cnt=1,i,f[1010];
int main()
{
scanf("%d",&n);
f[0]=f[1]=1;
for(i=2;i<=n;i++)
if(i&1) f[i]=f[i-1];
else f[i]=f[i-1]+f[i/2];
printf("%d\n",f[n]);
return 0;
}

19
1.1030.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<iostream>
using namespace std;
void beford(const string &in,const string &after)
{
if(in.size()>0)
{
char ch=after.back();
cout<<ch;
int k=in.find(ch);
beford(in.substr(0,k),after.substr(0,k));
beford(in.substr(k+1),after.substr(k,in.size()-k-1));
}
}
int main()
{
string a,b; cin>>a>>b;
beford(a,b); cout<<endl;
return 0;
}

14
1.1031.cpp Normal file
View File

@ -0,0 +1,14 @@
// luogu-judger-enable-o2
#include<cstdio>
const int maxn=105;
int n,a[maxn],s,res;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]),s+=a[i];
s/=n;
for(int i=0;i<n;i++) a[i]-=s;
for(int i=0;i<n;i++) if(a[i]!=0) a[i+1]+=a[i],res++;
printf("%d\n",res);
return 0;
}

16
1.1035.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<cstdio>
int main()
{
int n,k;
scanf("%d",&k);
double cnt=0;
n=1;
while(1)
{
cnt+=1.0/n;
if(cnt>k) break;
n++;
}
printf("%d\n",n);
return 0;
}

22
1.1036.cpp Normal file
View File

@ -0,0 +1,22 @@
#include<cstdio>
inline bool isp(int n)
{
for(int i=2;i*i<=n;i++) if(n%i==0) return false;
return n>=2;
}
int n,k,res;
int x[25];
int main()
{
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",&x[i]);
for(int i=0;i<(1<<n);i++)
if(__builtin_popcount(i)==k)
{
int s=0;
for(int j=0;j<n;j++) if(i&(1<<j)) s+=x[j];
if(isp(s)) res++;
}
printf("%d\n",res);
return 0;
}

44
1.1040.cpp Normal file
View File

@ -0,0 +1,44 @@
#include<cstdio>
using namespace std;
int n,v[31],dp[31][31],root[31][31],l,r;
void print(int l,int r)
{
if(l>r) return;
printf("%d ",root[l][r]);
print(l,root[l][r]-1);
print(root[l][r]+1,r);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&v[i]);
dp[i][i]=v[i];
root[i][i]=i;
}
for(int k=2;k<=n;k++)
for(int l=1;l+k-1<=n;l++)
{
r=l+k-1;
if(dp[l][r]<v[l]+dp[l+1][r])
{
dp[l][r]=v[l]+dp[l+1][r];
root[l][r]=l;
}
if(dp[l][r]<v[r]+dp[l][r-1])
{
dp[l][r]=v[r]+dp[l][r-1];
root[l][r]=r;
}
for(int i=l+1;i<=r-1;i++)
if(dp[l][i-1]*dp[i+1][r]+v[i]>dp[l][r])
{
dp[l][r]=v[i]+dp[l][i-1]*dp[i+1][r];
root[l][r]=i;
}
}
printf("%d\n",dp[1][n]);
print(1,n);
return 0;
}

14
1.1046.cpp Normal file
View File

@ -0,0 +1,14 @@
#include<cstdio>
int a[11];
int h;
int main()
{
for(int i=0;i<10;i++) scanf("%d",a+i);
scanf("%d",&h);
h+=30;
int res=0;
for(int i=0;i<10;i++)
if(h>=a[i]) res++;
printf("%d\n",res);
return 0;
}

19
1.1047.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<cstdio>
#include<cstring>
bool board[10005];
int main()
{
int L,m;
scanf("%d%d",&L,&m);
int a,b;
memset(board,1,sizeof(board));
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
memset(board+a,0,b-a+1);
}
int ans=0;
for(int i=0;i<=L;i++) ans+=board[i];
printf("%d\n",ans);
return 0;
}

16
1.1048.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[1005];
int n,T;
int w[105],v[105];
int main()
{
scanf("%d%d",&T,&n);
for(int i=1;i<=n;i++) scanf("%d%d",w+i,v+i);
for(int i=1;i<=n;i++)
for(int j=T;j>=w[i];j--)
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
printf("%d\n",dp[T]);
return 0;
}

16
1.1049.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int n,v,w;
int f[20005];
int main()
{
scanf("%d%d",&v,&n);
for(int i=0;i<n;i++)
{
scanf("%d",&w);
for(int j=v;j>=w;j--) f[j]=max(f[j-w]+w,f[j]);
}
printf("%d\n",v-f[v]);
return 0;
}

32
1.1052.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=2520;
const int maxmem=mod*105*10;
int L,S,T,M;
int stones[105],dp[maxmem];
bool flag[maxmem];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d%d%d",&L,&S,&T,&M);
for(int i=1;i<=M;i++) scanf("%d",&stones[i]);
sort(stones+1,stones+1+M);
stones[M+1]=L;
for(int i=1;i<=M+1;i++) stones[i]=stones[i-1]+(stones[i]-stones[i-1])%mod;
for(int i=1;i<=M;i++) flag[stones[i]]=true;
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
L=stones[M+1];
for(int i=1;i<=L+T;i++)
for(int j=S;j<=T;j++)
if(i-j>=0)
dp[i]=min(dp[i],dp[i-j]+flag[i]);
int res=dp[L];
for(int i=L;i<=L+T;i++) res=min(res,dp[i]);
printf("%d\n",res);
return 0;
}

18
1.1055.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<cstdio>
const int q[]={1,0,2,3,4,0,5,6,7,8,9};
char input[20];
int main()
{
int mod=0;
for(int i=0;i<11;i++)
{
input[i]=getchar();
mod+=q[i]*(input[i]-'0');
}
getchar();
int cro=getchar()-'0';
if(cro=='X'-'0') cro=10;
if(cro==mod%11) printf("Right\n");
else printf("%s-%c\n",input,mod%11==10?'X':'0'+mod%11);
return 0;
}

31
1.1056.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=2005;
int M,N,K,L,D;
struct Data { int id,cnt; };
inline bool cmp1(const Data &a,const Data &b) { return a.cnt>b.cnt; }
inline bool cmp2(const Data &a,const Data &b) { return a.id<b.id; }
Data R[maxn],C[maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d%d%d%d",&M,&N,&K,&L,&D);
for(int i=1;i<=M;i++) R[i].id=i;
for(int i=1;i<=N;i++) C[i].id=i;
for(int i=0;i<D;i++)
{
int x,y,p,q; scanf("%d%d%d%d",&x,&y,&p,&q);
if(x==p) C[min(y,q)].cnt++;
if(y==q) R[min(x,p)].cnt++;
}
sort(R+1,R+1+M,cmp1);
sort(R+1,R+1+K,cmp2);
sort(C+1,C+1+N,cmp1);
sort(C+1,C+1+L,cmp2);
for(int i=1;i<=K;i++) printf("%d ",R[i].id); puts("");
for(int i=1;i<=L;i++) printf("%d ",C[i].id); puts("");
return 0;
}

15
1.1059.cpp Normal file
View File

@ -0,0 +1,15 @@
#include<cstdio>
using namespace std;
int n,a[1001],res,t;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&t);
if(a[t]==0) a[t]=t,res++;
}
printf("%d\n",res);
for(int i=0;i<1001;i++) if(a[i]!=0) printf("%d ",a[i]);
return 0;
}

19
1.1060.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<iostream>
#include<algorithm>
using namespace std;
int w[30],v[30],f[50000];
int n,m;
int main()
{
cin>>m>>n;
for(int i=1;i<=n;i++)
{
cin>>v[i]>>w[i];
w[i]*=v[i];
}
for(int i=1;i<=n;i++)
for(int j=m;j>=v[i];j--)
f[j]=max(f[j],f[j-v[i]]+w[i]);
cout<<f[m]<<endl;
return 0;
}

30
1.1063.cpp Normal file
View File

@ -0,0 +1,30 @@
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=205;
int n,a[maxn],dp[maxn][maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
a[i+n]=a[i];
}
int len=n;
n=2*n-1;
for(int len=2;len<=n;len++)
for(int i=1;i+len-1<=n;i++)
{
int l=i,r=i+len-1;
for(int j=l;j<r;j++)
dp[l][r]=max(dp[l][r],dp[l][j]+dp[j+1][r]+a[l]*a[j+1]*a[r+1]);
}
int res=0;
for(int i=1;i+len-1<=n;i++) res=max(res,dp[i][i+len-1]);
printf("%d\n",res);
return 0;
}

49
1.1064.cpp Normal file
View File

@ -0,0 +1,49 @@
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
template<typename T> inline void read(T& t)
{
t=0; int ch,f=false;
while(ch=getchar(),!((ch>='0'&&ch<='9')||ch=='-'));
if(ch=='-') f=true,ch=getchar();
t=ch^48;
while(ch=getchar(),ch>='0'&&ch<='9') t=t*10+(ch^48);
if(f) t=-t;
}
template<typename T,typename... Args> inline void read(T& t,Args&... args) { read(t); read(args...); }
const int maxn=65;
const int maxm=32005;
int f[maxn][maxm];
vector<int> son[maxn];
int V[maxn],W[maxn];
int n,m,v,p,q;
int sz[maxn],suf[maxn],cnt;
void dfs(int u)
{
sz[u]=1;
for(int i=0;i<son[u].size();i++) { dfs(son[u][i]); sz[u]+=sz[son[u][i]]; }
suf[++cnt]=u;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
read(m,n);
for(int i=1;i<=n;i++)
{
read(v,p,q);
V[i]=v*p; W[i]=v; son[q].push_back(i);
}
dfs(0);
for(int i=1;i<=cnt;i++)
{
int now=suf[i];
for(int j=m;j>=0;j--)
if(j>=W[now]) f[i][j]=max(f[i-sz[now]][j],f[i-1][j-W[now]]+V[now]);
else f[i][j]=f[i-sz[now]][j];
}
printf("%d\n",f[cnt][m]);
return 0;
}

24
1.1067.cpp Normal file
View File

@ -0,0 +1,24 @@
#include<cstdio>
int n,x;
bool first=true;
int main()
{
scanf("%d",&n);
for(int i=n;i>=0;i--)
{
scanf("%d",&x);
if(x==0) continue;
if(x>0&&!first) printf("+");
if(x<0) printf("-"),x=-x;
if(i==0) printf("%d",x);
else
{
if(x!=1) printf("%d",x);
if(i==1) printf("x");
else printf("x^%d",i);
}
first=false;
}
printf("\n");
return 0;
}

40
1.1072.cpp Normal file
View File

@ -0,0 +1,40 @@
//http://contest-hunter.org:83/contest/0x30%E3%80%8C%E6%95%B0%E5%AD%A6%E7%9F%A5%E8%AF%86%E3%80%8D%E4%BE%8B%E9%A2%98/3201%20Hankson%E7%9A%84%E8%B6%A3%E5%91%B3%E9%A2%98
#include<cstdio>
#include<algorithm>
using namespace std;
int T,a0,a1,b0,b1;
int p[50000],v[50000],pcnt,res;
void cal(int p)
{
int ma0=0,ma1=0,mb0=0,mb1=0;
while(a0%p==0) ma0++,a0/=p;
while(a1%p==0) ma1++,a1/=p;
while(b0%p==0) mb0++,b0/=p;
while(b1%p==0) mb1++,b1/=p;
if(ma0==ma1&&mb0==mb1&&ma1<=mb1) { res*=(mb1-ma1+1); return; }
if((ma0>ma1&&mb0<mb1&&ma1==mb1)||(ma0>ma1&&mb0==mb1&&ma1<=mb1)||(ma0==ma1&&mb0<mb1&&ma1<=mb1)) return;
res=0;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
freopen("pro.out","w",stdout);
#endif
for(int i=1;i<50000;i++) v[i]=i;
for(int i=2;i<50000;i++)
{
if(v[i]==i) p[pcnt++]=i;
for(int j=0;j<pcnt&&p[j]*i<50000&&p[j]<=v[i];j++) v[p[j]*i]=p[j];
}
scanf("%d",&T);
while(T-->0)
{
scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
res=1;
for(int i=0;i<pcnt;i++) cal(p[i]);
if(b1>1&&b1!=a1) cal(b1);
printf("%d\n",res);
}
return 0;
}

35
1.1073.cpp Normal file
View File

@ -0,0 +1,35 @@
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int oo=0x3f3f3f3f;
const int maxn=100005;
vector<int> G[maxn];
int n,m,f[maxn],mi[maxn],a[maxn];
void dfs(int u,int mina,int p)
{
int flag=1;
mina=min(a[u],mina);
if(mi[u]>mina) mi[u]=mina,flag=0;
int maxx=max(f[p],a[u]-mina);
if(f[u]<maxx) { f[u]=maxx; flag=0; }
if(flag) return;
for(int i=0;i<G[u].size();i++) dfs(G[u][i],mina,u);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
{
int u,v,md;
scanf("%d%d%d",&u,&v,&md);
G[u].push_back(v);
if(md==2) G[v].push_back(u);
}
memset(mi,oo,sizeof(mi));
dfs(1,oo,0);
printf("%d\n",f[n]);
return 0;
}

110
1.1074.cpp Normal file
View File

@ -0,0 +1,110 @@
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=81*4+5;
const int maxnode=9*9*9*4*4+5;
const int Slot=0,Row=1,Col=2,Sub=3;
const int p[9][9]=
{
{6,6,6,6,6,6,6,6,6},
{6,7,7,7,7,7,7,7,6},
{6,7,8,8,8,8,8,7,6},
{6,7,8,9,9,9,8,7,6},
{6,7,8,9,10,9,8,7,6},
{6,7,8,9,9,9,8,7,6},
{6,7,8,8,8,8,8,7,6},
{6,7,7,7,7,7,7,7,6},
{6,6,6,6,6,6,6,6,6}
};
inline int encode(int a,int b,int c) { return a*81+b*9+c+1; }
inline void decode(int code,int &a,int &b,int &c)
{
code--;
c=code%9; code/=9;
b=code%9; code/=9;
a=code;
}
int res=-1,mp[9][9];
struct DLX
{
int n,sz;
int s[maxn];
int row[maxnode],col[maxnode];
int L[maxnode],R[maxnode],U[maxnode],D[maxnode];
void init(int n)
{
this->n=n;
sz=n+1;
memset(s,0,sizeof(s));
for(int i=0;i<=n;i++) { U[i]=i; D[i]=i; L[i]=i-1; R[i]=i+1; }
R[n]=0; L[0]=n;
}
void addNodes(int r,const vector<int> &columns)
{
int first=sz,c_sz=columns.size();
for(int i=0;i<c_sz;i++)
{
int c=columns[i];
L[sz]=sz-1; R[sz]=sz+1; D[sz]=c; U[sz]=U[c];
D[U[c]]=sz; U[c]=sz;
row[sz]=r; col[sz]=c;
s[c]++;sz++;
}
R[sz-1]=first; L[first]=sz-1;
}
#define For(i,A,s) for(int i=A[s];i!=s;i=A[i])
void remove(int c)
{
L[R[c]]=L[c];
R[L[c]]=R[c];
For(i,D,c) For(j,R,i) { U[D[j]]=U[j]; D[U[j]]=D[j]; --s[col[j]]; }
}
void restore(int c)
{
For(i,U,c) For(j,L,i) { ++s[col[j]]; U[D[j]]=j; D[U[j]]=j; }
L[R[c]]=c;
R[L[c]]=c;
}
bool dfs(int val)
{
if(R[0]==0) { res=max(res,val); return true; }
int c=R[0],flag=false;
For(i,R,0) if(s[i]<s[c]) c=i;
remove(c);
For(i,D,c)
{
For(j,R,i) remove(col[j]);
int nr,nc,nv;
decode(row[i],nr,nc,nv);
if(dfs(val+p[nr][nc]*(nv+1))) flag=true;
For(j,L,i) restore(col[j]);
}
restore(c);
return flag;
}
#undef For
};
DLX solver;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
For(r,0,8) For(c,0,8) scanf("%d",&mp[r][c]);
solver.init(9*9*4);
For(r,0,8) For(c,0,8) For(v,0,8)
if(mp[r][c]==0||mp[r][c]==v+1)
{
vector<int> cols;
cols.push_back(encode(Slot,r,c));
cols.push_back(encode(Row,r,v));
cols.push_back(encode(Col,c,v));
cols.push_back(encode(Sub,(r/3)*3+c/3,v));
solver.addNodes(encode(r,c,v),cols);
}
solver.dfs(0);
printf("%d\n",res);
return 0;
}

16
1.1075.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<cstdio>
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
int n;
scanf("%d",&n);
for(int i=2;i<=n;++i)
if(n%i==0)
{
printf("%d",n/i);
return 0;
}
return 0;
}

22
1.1082.cpp Normal file
View File

@ -0,0 +1,22 @@
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL exgcd(LL a,LL b,LL &x,LL &y)
{
if(b==0) { x=1; y=0; return a; }
LL d=exgcd(b,a%b,x,y);
LL z=x; x=y; y=z-(a/b)*y;
return d;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
LL a,b,x,y;
scanf("%lld%lld",&a,&b);
exgcd(a,b,x,y);
printf("%lld\n",(x%b+b)%b);
return 0;
}

11
1.1085.cpp Normal file
View File

@ -0,0 +1,11 @@
#include<cstdio>
int a[8],b[8];
int main()
{
for(int i=1;i<=7;i++) scanf("%d%d",a+i,b+i);
int res=0;
for(int i=1;i<=7;i++)
if(a[i]+b[i]>8&&a[i]+b[i]>a[res]+b[res]) res=i;
printf("%d\n",res);
return 0;
}

20
1.1087.cpp Normal file
View File

@ -0,0 +1,20 @@
#include<cstdio>
char s[1050];
void dfs(int L,int R)
{
if(L<R) dfs(L,(L+R)/2),dfs((L+R+1)/2,R);
int B=1,I=1;
for(int i=0;i<=R-L;i++)
if(s[L+i]=='1') B=false;
else if(s[L+i]=='0') I=false;
if(B) putchar('B');
else if(I) putchar('I');
else putchar('F');
}
int main()
{
int n;
scanf("%d%s",&n,s);
dfs(0,(1<<n)-1);
return 0;
}

33
1.1089.cpp Normal file
View File

@ -0,0 +1,33 @@
#include<cstdio>
int c,m,a[13];
int main()
{
for(int i=1;i<=12;i++) scanf("%d",a+i);
for(int i=1;i<=12;i++)
{
if(m+300<a[i])
{
printf("-%d",i);
return 0;
}
m+=300-a[i];
c+=m/100*100;
m%=100;
}
printf("%d",c/10*12+m);
return 0;
}
/*
290
230
280
200
300
170
330
50
90
80
200
60
*/

23
1.1090.cpp Normal file
View File

@ -0,0 +1,23 @@
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int n,x,res;
priority_queue<int,vector<int>,greater<int>> Q;
int main()
{
scanf("%d",&n);
while(n-->0)
{
scanf("%d",&x);
Q.push(x);
}
while(Q.size()>=2)
{
int a=Q.top(); Q.pop();
a+=Q.top(); Q.pop();
Q.push(a);
res+=a;
}
printf("%d\n",res);
return 0;
}

31
1.1091.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=105;
const int oo=0x3f3f3f3f;
int n,a[maxn],dp[maxn],pre[maxn],nxt[maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
memset(dp,oo,sizeof(dp));
for(int i=0;i<n;i++)
{
*lower_bound(dp,dp+n,a[i])=a[i];
pre[i]=lower_bound(dp,dp+n,oo)-dp;
}
memset(dp,oo,sizeof(dp));
for(int i=n-1;i>=0;i--)
{
*lower_bound(dp,dp+n,a[i])=a[i];
nxt[i]=lower_bound(dp,dp+n,oo)-dp;
}
int res=n;
for(int i=0;i<n;i++) res=min(res,n-(pre[i]+nxt[i]-1));
printf("%d\n",res);
return 0;
}

9
1.1100.cpp Normal file
View File

@ -0,0 +1,9 @@
#include<iostream>
using namespace std;
int main()
{
unsigned long long x;
cin>>x;
cout<<((x&0x0000ffff)<<16|(x&0xffff0000)>>16)<<endl;
return 0;
}

29
1.1108.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=5005;
int n,rlen=1,tot,a[maxn],f[maxn],cnt[maxn],useful[maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) f[i]=cnt[i]=useful[i]=1;
for(int i=2;i<=n;i++)
{
for(int j=i-1;j>=1;j--)
if(a[j]>a[i]&&useful[j])
{
if(f[j]+1==f[i]) cnt[i]+=cnt[j];
else if(f[j]+1>f[i]) { f[i]=f[j]+1; cnt[i]=cnt[j]; }
}
else if(a[j]==a[i]) { if(f[i]==1) useful[i]=0; break; }
rlen=max(rlen,f[i]);
}
for(int i=1;i<=n;i++) if(rlen==f[i]) tot+=cnt[i];
printf("%d %d\n",rlen,tot);
return 0;
}

16
1.1115.cpp Normal file
View File

@ -0,0 +1,16 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x,res,now;
int main()
{
scanf("%d%d",&n,&res); now=res;
for(int i=1;i<n;i++)
{
scanf("%d",&x);
now=max(now+x,x);
res=max(now,res);
}
printf("%d\n",res);
return 0;
}

63
1.1120.cpp Normal file
View File

@ -0,0 +1,63 @@
#include<cstdio>
#include<cstring>
const int N=70;
int n,cnt,tot,maxn,minn,tm[N];
bool ok;
void dfs(int need,int sum,int goal,int maxlen)
{
if(need==0)
{
printf("%d\n",goal);
ok=true;
}
if(sum==goal)//拼完了一根
{
dfs(need-1,0,goal,maxn);
return;
}
for(int i=maxlen;i>=minn;i--)//用单调性确保不重复
if(tm[i]&&i+sum<=goal)
{
tm[i]--;
dfs(need,sum+i,goal,i);
if(ok) return;
tm[i]++;
if(sum==0||sum+i==goal) break;
}
return;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
while(scanf("%d",&n)==1&&n)
{
minn=N ;
int x;
cnt=tot=maxn=0;
memset(tm,0,sizeof(tm));
while(n--)
{
scanf("%d",&x);
if(x<=50)
{
cnt++;
tm[x]++;//用桶更方便
tot+=x;
maxn=maxn>x?maxn:x;
minn=minn<x?minn:x;
}
}
x=tot/2;
ok=false;
for(int i=maxn;i<=x;i++)
if(tot%i==0)
{
dfs(tot/i,0,i,maxn);
if(ok) break;
}
if(!ok) printf("%d\n",tot);
}
return 0;
}

38
1.1122.cpp Normal file
View File

@ -0,0 +1,38 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=16005;
int n,a[maxn],f[maxn];
vector<int> G[maxn];
void dfs(int u,int fa)
{
f[u]=a[u];
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(v==fa) continue;
dfs(v,u);
if(f[v]>0) f[u]+=f[v];
}
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n-1;i++)
{
int u,v; scanf("%d%d",&u,&v);
G[v].push_back(u);
G[u].push_back(v);
}
dfs(1,-1);
int res=f[1];
for(int i=2;i<=n;i++) res=max(res,f[i]);
printf("%d\n",res);
return 0;
}

38
1.1131.cpp Normal file
View File

@ -0,0 +1,38 @@
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=500005;
int n,s; long long res;
vector<int> G[maxn],V[maxn];
int dfs(int u,int fa)
{
int maxv=0;
vector<int> dep;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(v==fa) continue;
int w=dfs(v,u)+V[u][i];
maxv=max(maxv,w);
dep.push_back(w);
}
for(int i=0;i<dep.size();i++) res+=maxv-dep[i];
return maxv;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&s);
for(int i=0;i<n-1;i++)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
G[a].push_back(b); G[b].push_back(a);
V[a].push_back(c); V[b].push_back(c);
}
dfs(s,-1);
printf("%lld\n",res);
return 0;
}

42
1.1137.cpp Normal file
View File

@ -0,0 +1,42 @@
#include<cstdio>
#include<algorithm>
#include<vector>
#include<stack>
#include<cassert>
using namespace std;
const int maxn=100005;
int n,m,f[maxn];
vector<int> G[maxn];
int in[maxn],tp[maxn],cnt;
stack<int> stk;
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
int x,y; scanf("%d%d",&x,&y);
G[x].push_back(y); in[y]++;
}
for(int i=1;i<=n;i++) if(in[i]==0) { tp[++cnt]=i; stk.push(i); }
while(stk.size())
{
int u=stk.top(); stk.pop();
for(int v:G[u])
{
in[v]--;
if(!in[v]) { tp[++cnt]=v; stk.push(v); }
}
}
for(int i=1;i<=n;i++) f[i]=1;
assert(cnt==n);
for(int i=1;i<=n;i++)
{
int u=tp[i];
for(int v:G[u]) f[v]=max(f[v],f[u]+1);
}
for(int i=1;i<=n;i++) printf("%d\n",f[i]);
return 0;
}

19
1.1138.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=10005;
int n,k,a[maxn];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
a[0]=-1;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
{
if(a[i]!=a[i-1]) k--;
if(!k) { printf("%d\n",a[i]); return 0; }
}
puts("NO RESULT");
return 0;
}

48
1.1141.cpp Normal file
View File

@ -0,0 +1,48 @@
// luogu-judger-enable-o2
#include<cstdio>
#include<queue>
using namespace std;
const int dr[]={-1,1,0,0};
const int dc[]={0,0,-1,1};
struct node { int r,c; };
const int maxn=1005;
char mp[maxn][maxn];
int idx[maxn][maxn],cnt[maxn*maxn];
int n,m,icnt;
void bfs(int r,int c,int id)
{
idx[r][c]=id;
queue<node> que;
que.push((node){r,c});
while(que.size())
{
cnt[id]++;
node u=que.front(); que.pop();
for(int i=0;i<4;i++)
{
node v=(node){u.r+dr[i],u.c+dc[i]};
if(v.r>=1&&v.r<=n&&v.c>=1&&v.c<=n&&!idx[v.r][v.c]&&mp[u.r][u.c]!=mp[v.r][v.c])
{
idx[v.r][v.c]=id;
que.push(v);
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",&mp[i][1]);
int r,c;
while(m-->0)
{
scanf("%d%d",&r,&c);
if(idx[r][c]) printf("%d\n",cnt[idx[r][c]]);
else
{
bfs(r,c,++icnt);
printf("%d\n",cnt[icnt]);
}
}
return 0;
}

15
1.1147.cpp Normal file
View File

@ -0,0 +1,15 @@
#include<cstdio>
int l,r,sum,M;
int main()
{
scanf("%d",&M);
l=r=sum=1;
while(r<M)
{
while(sum+r+1<=M) sum+=++r;
if(sum==M) printf("%d %d\n",l,r);
sum-=l++;
if(l>r) r=sum=l;
}
return 0;
}

22
1.1149.cpp Normal file
View File

@ -0,0 +1,22 @@
#include<cstdio>
int main()
{
int a[2001]={6},n,c[]={6,2,5,5,4,5,6,3,7,6},s=0;
scanf("%d",&n);
for(int i=1;i<=2000;i++)
{
int j=i;
while(j>0)
{
a[i]+=c[j%10];
j/=10;
}
}
for(int i=0;i<=1000;i++)
{
for(int j=0;j<=1000;j++)
if(a[i]+a[j]+a[i+j]+4==n) s++;
}
printf("%d",s);
return 0;
}

14
1.1151.cpp Normal file
View File

@ -0,0 +1,14 @@
#include<iostream>
using namespace std;
int main()
{
int k,flg=1; cin>>k;
for(int a=1;a<=3;a++) for(int b=0;b<=9;b++) for(int c=0;c<=9;c++) for(int d=0;d<=9;d++) for(int e=0;e<=9;e++)
if(a*10000+b*1000+c*100+d*10+e<=30000&&(a*100+b*10+c)%k==0&&(b*100+c*10+d)%k==0&&(c*100+d*10+e)%k==0)
{
flg=0;
cout<<a<<b<<c<<d<<e<<endl;
}
if(flg) cout<<"No"<<endl;
return 0;
}

68
1.1155.cpp Normal file
View File

@ -0,0 +1,68 @@
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
const int oo=0x3f3f3f3f;
const int maxn=1005;
int n;
int a[maxn],f[maxn],vis[maxn];
vector<int> G[maxn];
void dfs(int u,int c)
{
if(vis[u]!=-1&&vis[u]!=c) { printf("0\n"); exit(0); }
if(vis[u]!=-1) return;
vis[u]=c;
for(int i=0;i<G[u].size();i++) dfs(G[u][i],c^1);
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
f[n+1]=oo;
for(int i=n;i>=1;i--) f[i]=min(f[i+1],a[i]);
for(int i=1;i<n;i++)
for(int j=i+1;j<n;j++)
if(f[j+1]<a[i]&&a[i]<a[j])
{
G[j].push_back(i);
G[i].push_back(j);
}
memset(vis,-1,sizeof(vis));
for(int i=1;i<=n;i++) if(vis[i]==-1) dfs(i,1);
stack<int> s1,s2;
int now=1;
for(int i=1;i<=n;i++)
{
if(vis[i]==1)
{
printf("a ");
s1.push(a[i]);
}
else
{
printf("c ");
s2.push(a[i]);
}
while((s1.size()&&s1.top()==now)||(s2.size()&&s2.top()==now))
{
if(s1.size()&&s1.top()==now)
{
printf("b ");
s1.pop();
}
else
{
printf("d ");
s2.pop();
}
now++;
}
}
return 0;
}

26
1.1156.cpp Normal file
View File

@ -0,0 +1,26 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int d,n,f[105];
struct Data { int t,f,h; };
Data a[105];
inline bool cmp(const Data &a,const Data &b) { return a.t<b.t; }
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
f[0]=10;
scanf("%d%d",&d,&n);
for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i].t,&a[i].f,&a[i].h);
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++) for(int j=d;j>=0;j--) if(f[j]>=a[i].t)
{
if(j+a[i].h>=d) { printf("%d\n",a[i].t); return 0; }
f[j+a[i].h]=max(f[j+a[i].h],f[j]);
f[j]+=a[i].f;
}
printf("%d\n",f[0]);
return 0;
}

32
1.1162.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<cstdio>
int mp[35][35],n;
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
void dfs(int x,int y,int fill)
{
if(x<=0||y<=0||x>n||y>n||mp[x][y]!=0) return;
mp[x][y]=fill;
for(int i=0;i<4;i++)
dfs(x+dx[i],y+dy[i],fill);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&(mp[j][i]));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(j==1||i==1||j==n||i==n) dfs(j,i,-1);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dfs(j,i,2);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
if(mp[j][i]==-1) printf("0 ");
else printf("%d ",mp[j][i]);
printf("\n");
}
return 0;
}

36
1.1169.cpp Normal file
View File

@ -0,0 +1,36 @@
#include<cstdio>
#include<algorithm>
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Ford(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=2005;
int n,m,a[maxn][maxn],MaxS,MaxJ,lef[maxn][maxn],rig[maxn][maxn],up[maxn][maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
For(i,1,n) For(j,1,m) scanf("%d",&a[i][j]);
For(i,1,n)
{
lef[i][1]=1; rig[i][m]=m;
For(j,2,m) lef[i][j]=(a[i][j]!=a[i][j-1]?lef[i][j-1]:j);
Ford(j,m-1,1) rig[i][j]=(a[i][j]!=a[i][j+1]?rig[i][j+1]:j);
}
For(i,1,n) For(j,1,m)
{
up[i][j]=1;
if(i>1&&a[i][j]!=a[i-1][j])
{
lef[i][j]=max(lef[i][j],lef[i-1][j]);
rig[i][j]=min(rig[i][j],rig[i-1][j]);
up[i][j]=up[i-1][j]+1;
}
int wide=rig[i][j]-lef[i][j]+1,len=min(wide,up[i][j]);
MaxS=max(MaxS,len*len);
MaxJ=max(MaxJ,wide*up[i][j]);
}
printf("%d\n%d\n",MaxS,MaxJ);
return 0;
}

18
1.1177.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int maxn=100005;
int n,a[maxn];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
for(int i=0;i<n;i++) printf("%d ",a[i]); puts("");
return 0;
}

19
1.1179.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<cstdio>
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
int L,R,res=0; scanf("%d%d",&L,&R);
for(int i=L;i<=R;i++)
{
int x=i;
while(x)
{
if(x%10==2) res++;
x/=10;
}
}
printf("%d\n",res);
return 0;
}

15
1.1181.cpp Normal file
View File

@ -0,0 +1,15 @@
// luogu-judger-enable-o2
#include<cstdio>
int n,m,res=1,now,x;
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d",&x);
if(now+x>m) res++,now=x;
else now+=x;
}
printf("%d\n",res);
return 0;
}

16
1.1192.cpp Normal file
View File

@ -0,0 +1,16 @@
// luogu-judger-enable-o2
#include<cstdio>
const int mod=100003;
int f[100007],n,k;
int main()
{
scanf("%d%d",&n,&k);
f[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k&&j<=i;j++) f[i]+=f[i-j];
f[i]=f[i]%mod;
}
printf("%d",f[n]);
return 0;
}

44
1.1196.cpp Normal file
View File

@ -0,0 +1,44 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=30005;
int M,fa[maxn],d[maxn],sz[maxn];
inline int ff(int u)
{
int a=u,b,c=0;
while(u!=fa[u]) c+=d[u],u=fa[u];
while(a!=u)
{
b=fa[a];
c-=d[a];
d[a]+=c;
fa[a]=u;
a=b;
}
return u;
}
inline void merge(int x,int y)
{
x=ff(x); y=ff(y);
fa[x]=y; d[x]=sz[y]; sz[y]+=sz[x];
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&M);
for(int i=1;i<=30000;i++) fa[i]=i,sz[i]=1;
while(M-->0)
{
char op; int x,y; scanf("%s %d %d",&op,&x,&y);
if(op=='M') merge(x,y);
else
{
if(ff(x)!=ff(y)) puts("-1");
else printf("%d\n",abs(d[x]-d[y])-1);
}
}
return 0;
}

27
1.1217.cpp Normal file
View File

@ -0,0 +1,27 @@
#include<cstdio>
#define For(i,a,b) for(int i=a;i<=b;i++)
int hws[100005],cnt;
int L,R;
inline bool isp(int n)
{
for(int i=2;i*i<=n;i++) if(n%i==0) return false;
return n>=2;
}
int main()
{
scanf("%d%d",&L,&R);
For(a,0,9) For(b,0,9) For(c,0,9) For(d,0,9) For(e,0,9)
{
if(d==0&&c==0&&b==0&&a==0&&e==9) hws[cnt++]=11;
if(d==0&&c==0&&b==0&&a==0) hws[cnt++]=e;
else if(c==0&&b==0&&a==0) hws[cnt++]=e*10+d*101;
else if(b==0&&a==0) hws[cnt++]=e*100+d*1010+c*10001;
else if(a==0) hws[cnt++]=e*1000+d*10100+c*100010+b*1000001;
else hws[cnt++]=e*10000
+d*101000+c*1000100+b*10000010
+a*100000001;
}
for(int i=0;i<cnt;i++)
if(L<=hws[i]&&hws[i]<=R&&isp(hws[i])) printf("%d\n",hws[i]);
return 0;
}

31
1.1219.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<cstdio>
#include<cstring>
int n,cnt;
int res[20];
void dfs(int step,int a,int b,int c)
{
if(step>=n)
{
if(cnt++<3)
{
printf("%d",res[0]);
for(int i=1;i<n;i++) printf(" %d",res[i]);
printf("\n");
}
return;
}
int cant=a|b|c;
for(int i=1;i<=n;i++)
if(!(cant&(1<<i)))
{
res[step]=i;
dfs(step+1,a|(1<<i),(b|(1<<i))<<1,(c|(1<<i))>>1);
}
}
int main()
{
scanf("%d",&n);
dfs(0,0,0,0);
printf("%d\n",cnt);
return 0;
}

29
1.1220.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=55;
int n,c,p[maxn],w[maxn];
LL s[maxn],f[maxn][maxn][2];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++) scanf("%d%d",&p[i],&w[i]);
for(int i=1;i<=n;i++) s[i]=s[i-1]+w[i];
memset(f,0x3f,sizeof(f));
f[c][c][0]=f[c][c][1]=0;
for(int len=1;len<n;len++)
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
LL W=s[i-1]+s[n]-s[j];
if(i>1) f[i-1][j][0]=min(f[i-1][j][0],min(f[i][j][0]+(p[i]-p[i-1])*W,f[i][j][1]+(p[j]-p[i-1])*W));
if(j<n) f[i][j+1][1]=min(f[i][j+1][1],min(f[i][j][0]+(p[j+1]-p[i])*W,f[i][j][1]+(p[j+1]-p[j])*W));
}
printf("%lld\n",min(f[1][n][0],f[1][n][1]));
return 0;
}

22
1.1223.cpp Normal file
View File

@ -0,0 +1,22 @@
// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
using namespace std;
struct node { int ti,id; };
inline bool operator<(const node a,const node b) { return a.ti<b.ti; }
node p[1005];
int n;
double s=0.0;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&p[i].ti),p[i].id=i+1;
sort(p,p+n);
for(int i=0;i<n;i++)
{
printf("%d ",p[i].id);
s+=p[i].ti*(n-i-1);
}
printf("\n%.2lf\n",s/n);
return 0;
}

19
1.1226.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<cstdio>
typedef long long LL;
LL ksm(LL a,LL b,LL p)
{
LL res=1;
for(;b>0;b>>=1)
{
if(b&1) res=res*a%p;
a=a*a%p;
}
return res%p;
}
LL b,p,k;
int main()
{
scanf("%lld%lld%lld",&b,&p,&k);
printf("%lld^%lld mod %lld=%lld",b,p,k,ksm(b,p,k));
return 0;
}

829
1.1255.cpp Normal file
View File

@ -0,0 +1,829 @@
#include<bits/stdc++.h>
//main codes====================\/
#ifndef BIGINT
#define BIGINT
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
template<class T_queue>
struct Node_queue_for_bigint
{
T_queue num;
Node_queue_for_bigint *next;
Node_queue_for_bigint()
{
next=0;
}
};
template<class a_queue>
struct queue_for_bigint
{
Node_queue_for_bigint<a_queue> *head,*tail,*L;
bool isn;
int SIZE_queue;
void beginning()
{
head=tail=L=0;
isn=0;
head=tail=new Node_queue_for_bigint<a_queue>;
tail->next=head;
SIZE_queue=0;
isn=1;
}
queue_for_bigint()
{
beginning();
}
~queue_for_bigint()
{
Node_queue_for_bigint<a_queue> *p=head,*tp;
p=p->next;
while(p!=head)
{
tp=p->next;
delete p;
p=tp;
}
}
bool push(a_queue s)
{
SIZE_queue++;
tail->num=s;
if(tail->next==head)
{
tail->next=new Node_queue_for_bigint<a_queue>;
tail->next->next=head;
L=tail;
tail=tail->next;
return 1;
}
L=tail;
tail=tail->next;
return 0;
}
bool pop()
{
if(head==tail) return 1;
head=head->next;
SIZE_queue--;
return 0;
}
a_queue& front()
{
return head->num;
}
a_queue& back()
{
return L->num;
}
int size()
{
return SIZE_queue;
}
void clear()
{
SIZE_queue=0;
tail=head;
}
bool operator=(queue_for_bigint<a_queue>b)
{
if(!isn)
{
this->beginning();
isn=1;
}
this->clear();
Node_queue_for_bigint<a_queue> *p=b.head;
while(p!=b.tail)
{
this->push(p->num);
p=p->next;
}
}
};
int CacheSize=25;//try to use the cache
queue_for_bigint<char*> Mems;
queue_for_bigint<int> q;
queue_for_bigint<char> cache;
struct BigInt
{
char f:4,nAn:4;
std::vector<int> num;
static const int base=100000000;
BigInt()
{
f=0;
nAn=0;
num.push_back(0);
}
template<class TYPE>
BigInt(TYPE V)
{
f=nAn=0;
*this=V;
}
void format()
{
while(num.size()>1&&num[num.size()-1]<=0) num.erase(num.end()-1);
if(num.size()==1&&num[0]==0) f=0;
if(num.size()==0) num.push_back(0),f=nAn=0;
}
//Input and Output
char* c_str()
{
char *p,*ptr;
if(!nAn)
{
p=new char[num.size()*8+16];
ptr=p;
memset(p,0,num.size()*8+16);
if(f) sprintf(p,"-"),p++;
sprintf(p,"%d",num[num.size()-1]);
for(int i=num.size()-2;i>=0;i--)
{
while(*p) p++;
sprintf(p,"%08d",num[i]);
}
}
else
{
p=new char[5];
sprintf(p,"nan");
}
Mems.push(ptr);
return ptr;
}
std::string str()
{
std::string ss=c_str();
return ss;
}
BigInt operator=(char* s)
{
f=0;
if(s==0) return BigInt();
if(*s=='-')
{
f=1;
s++;
}
int len=strlen(s),add=0,i,t;
num.resize(len/8+1);
char *p=s+len-1;
while(p>=s)
{
t=0;
for(i=-7;i<=0;i++)
if(p+i>=s) t=t*10+*(p+i)-'0';
p-=8;
num[add++]=t;
}
while(num.size()>add) num.erase(num.end()-1);
return *this;
}
BigInt operator=(std::string ss)
{
char *s=&ss[0];
f=0;
if(s==0) return BigInt();
if(*s=='-')
{
f=1;
s++;
}
int len=strlen(s),add=0,i,t;
num.resize(len/8+1);
char *p=s+len-1;
while(p>=s)
{
t=0;
for(i=-7;i<=0;i++)
if(p+i>=s) t=t*10+*(p+i)-'0';
p-=8;
num[add++]=t;
}
while(num.size()>add) num.erase(num.end()-1);
return *this;
}
BigInt operator=(int v)
{
f=0;
if(v<0)
{
f=1;
v=-v;
}
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator=(unsigned int v)
{
f=0;
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator=(long long v)
{
f=0;
if(v<0)
{
f=1;
v=-v;
}
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator=(unsigned long long v)
{
f=0;
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
//====================/
//In-situ operation
BigInt operator++()
{
format();
if(!f)
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
else
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
format();
}
return *this;
}
BigInt operator++(int)
{
format();
BigInt t=*this;
if(!f)
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
else
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
format();
}
return t;
}
BigInt operator--()
{
format();
if(!f)
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
if(num[i-1]<0)
*this=-1;
format();
}
else
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
return *this;
}
BigInt operator--(int)
{
format();
BigInt t=*this;
if(!f)
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
if(num[i-1]<0)
*this=-1;
format();
}
else
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
return t;
}
//=====================/
};
//compare operations
bool operator<(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return a.f>b.f;
if(a.f==0)
{
if(a.num.size()<b.num.size()) return 1;
else if(a.num.size()>b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]<b.num[i]) return 1;
else if(a.num[i]>b.num[i]) return 0;
}
else
{
if(a.num.size()>b.num.size()) return 1;
else if(a.num.size()<b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]>b.num[i]) return 1;
else if(a.num[i]<b.num[i]) return 0;
}
return 0;
}
bool operator==(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return 0;
if(a.num.size()!=b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]!=b.num[i]) return 0;
return 1;
}
bool operator!=(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return 1;
if(a.num.size()!=b.num.size()) return 1;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]!=b.num[i]) return 1;
return 0;
}
bool operator>(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return a.f<b.f;
if(a.f==0)
{
if(a.num.size()>b.num.size()) return 1;
else if(a.num.size()<b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]>b.num[i]) return 1;
else if(a.num[i]<b.num[i]) return 0;
}
else
{
if(a.num.size()<b.num.size()) return 1;
else if(a.num.size()>b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]<b.num[i]) return 1;
else if(a.num[i]>b.num[i]) return 0;
}
return 0;
}
bool operator<=(BigInt a,BigInt b){return (a<b||a==b);}
bool operator>=(BigInt a,BigInt b){return (a>b||a==b);}
//=================/
//maths operations
BigInt operator+(BigInt a,BigInt b);
BigInt operator-(BigInt a,BigInt b);
BigInt operator*(BigInt a,BigInt b);
BigInt operator/(BigInt a,BigInt b);
void BigInt_add (BigInt &a,BigInt &b,BigInt &c);
void BigInt_minus (BigInt &a,BigInt &b,BigInt &c);
void BigInt_times (BigInt &a,BigInt &b,BigInt &c);
void BigInt_divide (BigInt &a,BigInt &b,BigInt &c);
void BigInt_add(BigInt &a,BigInt &b,BigInt &c)
{
a.format();
b.format();
c.nAn=(a.nAn==1||b.nAn==1);
if(c.nAn) return;
if(a.f)
{
if(b.f)
{
a.f=b.f=0;
BigInt_add(a,b,c);
a.f=b.f=c.f=1;
return;
}
else
{
a.f=0;
BigInt_minus(b,a,c);
a.f=1;
return;
}
}
else if(b.f)
{
b.f=0;
BigInt_minus(a,b,c);
b.f=1;
return;
}
int t=0,t2=std::max(a.num.size(),b.num.size())+1;
c.num.resize(t2);
memset(&c.num[0],0,t2*4);
for(int i=0;i<t2;i++)
{
if(i<a.num.size()) t+=a.num[i];
if(i<b.num.size()) t+=b.num[i];
c.num[i]=t%BigInt::base;
t/=BigInt::base;
}
c.format();
}
BigInt operator+(BigInt a,BigInt b)
{
BigInt t;
BigInt_add(a,b,t);
return t;
}
BigInt operator+=(BigInt &a,BigInt b)
{
BigInt t;
BigInt_add(a,b,t);
return a=t;
}
void BigInt_minus(BigInt &a,BigInt &b,BigInt &c)
{
a.format();
b.format();
c.nAn=(a.nAn==1||b.nAn==1);
if(c.nAn) return;
if(a.f)
{
if(b.f)
{
a.f=b.f=0;
BigInt_minus(b,a,c);
a.f=b.f=1;
return;
}
else
{
a.f=0;
BigInt_add(a,b,c);
a.f=c.f=1;
return;
}
}
else if(b.f)
{
b.f=0;
BigInt_add(a,b,c);
b.f=1;
return;
}
if(a<b)
{
c=b-a;
c.f=1;
return;
}
c=a;
int z=0,k;
for(int i=0;i<b.num.size();i++)
{
c.num[i]=c.num[i]-b.num[i];
if(c.num[i]<0)
{
c.num[i]+=BigInt::base;
z=1;
}
else z=0;
k=i+1;
while(z&&k<c.num.size())
{
c.num[k]--;
if(c.num[k]<0)
{
z=1;
c.num[k]+BigInt::base;
}
else z=0;
k++;
}
}
c.format();
}
BigInt operator-(BigInt a,BigInt b)
{
BigInt t;
BigInt_minus(a,b,t);
return t;
}
BigInt operator-=(BigInt &a,BigInt b)
{
BigInt t;
BigInt_minus(a,b,t);
return a=t;
}
void BigInt_times(BigInt &a,BigInt &b,BigInt &c)
{
a.format();
b.format();
c.nAn=(a.nAn==1||b.nAn==1);
if(c.nAn) return;
c.num.resize(a.num.size()+b.num.size());
memset(&c.num[0],0,(a.num.size()+b.num.size())*4);
int i,j,k,I,J;
long long t;
int *A,*B,*C,As=a.num.size(),Bs=b.num.size();
A=&(a.num[0]);
B=&(b.num[0]);
C=&(c.num[0]);
for(i=0;i<As;i+=CacheSize)
for(j=0;j<Bs;j+=CacheSize)
for(I=i;I<i+CacheSize&&I<As;I++)
for(J=j;J<j+CacheSize&&J<Bs;J++)
{
t=(long long)A[I]*B[J];
t=t+C[I+J];
C[I+J]=t%BigInt::base;
k=I+J+1;
t/=BigInt::base;
while(t>0)
{
t=t+C[k];
C[k++]=t%BigInt::base;
t=t/BigInt::base;
}
}
c.f=(a.f!=b.f);
c.format();
}
BigInt operator*(BigInt a,BigInt b)
{
BigInt t;
BigInt_times(a,b,t);
return t;
}
BigInt operator*=(BigInt &a,BigInt b)
{
BigInt t;
BigInt_times(a,b,t);
return a=t;
}
void BigInt_divide(BigInt &a,BigInt &b,BigInt &c)
{
BigInt t;
a.format();
b.format();
bool af=a.f,bf=b.f;
a.f=b.f=0;
if(a<b)
{
c=BigInt();
return;
}
c.nAn=(a.nAn==1||b.nAn==1||(b.num.size()==1&&b.num[0]==0));
if(c.nAn) return;
c.f=(af!=bf);
c.num.resize(a.num.size()-b.num.size()+1,0);
int L,R;
for(int i=c.num.size()-1;i>=0;i--)
{
L=0;
R=a.base-1;
while(L+1<R)
{
c.num[i]=(L+R)/2;
BigInt_times(b,c,t);
if(t>a) R=(L+R)/2;
else L=(L+R)/2;
}
c.num[i]=L;
}
c.format();
}
BigInt operator/(BigInt a,BigInt b)
{
BigInt c;
BigInt_divide(a,b,c);
return c;
}
BigInt operator/=(BigInt &a,BigInt b)
{
BigInt c;
BigInt_divide(a,b,c);
return a=c;
}
BigInt operator%(BigInt a,BigInt b)
{
BigInt t1,t2;
BigInt_divide(a,b,t1);
BigInt_times(t1,b,t2);
BigInt_minus(a,t2,t1);
return t1;
}
BigInt operator%=(BigInt &a,BigInt b)
{
BigInt t1,t2;
BigInt_divide(a,b,t1);
BigInt_times(t1,b,t2);
BigInt_minus(a,t2,t1);
return a=t1;
}
void free_pointers()//Releasing temporary memory
{
while(Mems.size()>0)
{
delete[] Mems.front();
Mems.pop();
}
}
//======================/
int read(BigInt &n,FILE *stream=stdin)
{
cache.clear();
char t;
while(!feof(stream))
{
fread(&t,1,1,stream);
if(t=='-'||(t>='0'&&t<='9'))
{
ungetc(t,stream);
break;
}
}
bool flag=0;
while(!feof(stream))
{
fread(&t,1,1,stream);
if(t!='-')
{
ungetc(t,stream);
break;
}
flag=!flag;
}
if(flag) cache.push('-');
while(!feof(stream))
{
fread(&t,1,1,stream);
if(t<'0'||t>'9')
{
ungetc(t,stream);
break;
}
cache.push(t);
}
char *p=new char[cache.size()+1],*tp;
memset(p,0,cache.size()+1);
tp=p;
while(cache.size()>0) *tp++=cache.front(),cache.pop();
n=p;
delete[] p;
}
int write(BigInt n,FILE *stream=stdout)
{
n.format();
if(n.nAn) fprintf(stream,"nan");
else
{
if(n.f) fprintf(stream,"-");
fprintf(stream,"%d",n.num[n.num.size()-1]);
for(int i=n.num.size()-2;i>=0;i--)
fprintf(stream,"%08d",n.num[i]);
}
}
#endif
//stream input and output
#ifdef _GLIBCXX_OSTREAM
std::ostream& operator<<(std::ostream& str,BigInt n)
{
n.format();
if(n.nAn) str<<"nan";
else
{
if(n.f) str<<'-';
str<<n.num[n.num.size()-1];
str.fill('0');
str.width(8);
for(int i=n.num.size()-2;i>=0;i--)
str<<n.num[i];
str.fill(0);
str.width(0);
}
return str;
}
#endif
#ifdef _GLIBCXX_ISTREAM
std::istream& operator>>(std::istream& str,BigInt &n)
{
cache.clear();
while(!str.eof()&&!(str.peek()=='-'||(str.peek()>='0'&&str.peek()<='9')))
str.get();
bool flag=0;
while(!str.eof()&&str.peek()=='-') flag=!flag,str.get();
if(flag) cache.push('-');
while(!str.eof()&&str.peek()>='0'&&str.peek()<='9') cache.push(str.get());
char *p=new char[cache.size()+1],*t;
memset(p,0,cache.size()+1);
t=p;
while(cache.size()>0) *t++=cache.front(),cache.pop();
n=p;
delete[] p;
return str;
}
#endif
//======================/
//=========================/\
using namespaec std;
int main()
{
BigInt a=0,b=1,c=0;
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
}
printf("%s\n",c.c_str());
return 0;
}

47
1.1273.cpp Normal file
View File

@ -0,0 +1,47 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=3005;
struct Edge { int v,w; Edge *nxt; };
int n,m,a[maxn],f[maxn][maxn],t[maxn];
Edge mem[maxn],*G[maxn],*ecnt=mem;
inline void AddEdge(int u,int v,int w) { ecnt->v=v; ecnt->w=w; ecnt->nxt=G[u]; G[u]=ecnt++; }
int dfs(int u)
{
if(u>n-m)
{
f[u][1]=a[u];
return 1;
}
int tot=0,v,sz;
for(Edge *it=G[u];it;it=it->nxt)
{
v=it->v; sz=dfs(v);
for(int i=0;i<=tot;i++) t[i]=f[u][i];
for(int i=0;i<=tot;i++)
for(int j=0;j<=sz;j++)
f[u][i+j]=max(f[u][i+j],t[i]+f[v][j]-it->w);
tot+=sz;
}
return tot;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n-m;i++)
{
int tot,v,w;
scanf("%d",&tot);
while(tot-->0) { scanf("%d%d",&v,&w); AddEdge(i,v,w); }
}
for(int i=n-m+1;i<=n;i++) scanf("%d",&a[i]);
memset(f,~0x3f,sizeof(f));
for(int i=1;i<=n;i++) f[i][0]=0;
dfs(1);
for(int i=m;i>=0;i--) if(f[1][i]>=0) { printf("%d\n",i); return 0; }
return 0;
}

825
1.1303.cpp Normal file
View File

@ -0,0 +1,825 @@
#include<iostream>
//main codes====================\/
#ifndef BIGINT
#define BIGINT
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
template<class T_queue>
struct Node_queue_for_bigint
{
T_queue num;
Node_queue_for_bigint *next;
Node_queue_for_bigint()
{
next=0;
}
};
template<class a_queue>
struct queue_for_bigint
{
Node_queue_for_bigint<a_queue> *head,*tail,*L;
bool isn;
int SIZE_queue;
void beginning()
{
head=tail=L=0;
isn=0;
head=tail=new Node_queue_for_bigint<a_queue>;
tail->next=head;
SIZE_queue=0;
isn=1;
}
queue_for_bigint()
{
beginning();
}
~queue_for_bigint()
{
Node_queue_for_bigint<a_queue> *p=head,*tp;
p=p->next;
while(p!=head)
{
tp=p->next;
delete p;
p=tp;
}
}
bool push(a_queue s)
{
SIZE_queue++;
tail->num=s;
if(tail->next==head)
{
tail->next=new Node_queue_for_bigint<a_queue>;
tail->next->next=head;
L=tail;
tail=tail->next;
return 1;
}
L=tail;
tail=tail->next;
return 0;
}
bool pop()
{
if(head==tail) return 1;
head=head->next;
SIZE_queue--;
return 0;
}
a_queue& front()
{
return head->num;
}
a_queue& back()
{
return L->num;
}
int size()
{
return SIZE_queue;
}
void clear()
{
SIZE_queue=0;
tail=head;
}
bool operator=(queue_for_bigint<a_queue>b)
{
if(!isn)
{
this->beginning();
isn=1;
}
this->clear();
Node_queue_for_bigint<a_queue> *p=b.head;
while(p!=b.tail)
{
this->push(p->num);
p=p->next;
}
return 0;
}
};
int CacheSize=25;//try to use the cache
queue_for_bigint<char*> Mems;
queue_for_bigint<int> q;
queue_for_bigint<char> cache;
struct BigInt
{
char f:4,nAn:4;
std::vector<int> num;
static const int base=100000000;
BigInt()
{
f=0;
nAn=0;
num.push_back(0);
}
template<class TYPE>
BigInt(TYPE V)
{
f=nAn=0;
*this=V;
}
void format()
{
while(num.size()>1&&num[num.size()-1]<=0) num.erase(num.end()-1);
if(num.size()==1&&num[0]==0) f=0;
if(num.size()==0) num.push_back(0),f=nAn=0;
}
//Input and Output
char* c_str()
{
char *p,*ptr;
if(!nAn)
{
p=new char[num.size()*8+16];
ptr=p;
memset(p,0,num.size()*8+16);
if(f) sprintf(p,"-"),p++;
sprintf(p,"%d",num[num.size()-1]);
for(int i=num.size()-2;i>=0;i--)
{
while(*p) p++;
sprintf(p,"%08d",num[i]);
}
}
else
{
p=new char[5];
sprintf(p,"nan");
}
Mems.push(ptr);
return ptr;
}
std::string str()
{
std::string ss=c_str();
return ss;
}
BigInt operator=(char* s)
{
f=0;
if(s==0) return BigInt();
if(*s=='-')
{
f=1;
s++;
}
int len=strlen(s),add=0,i,t;
num.resize(len/8+1);
char *p=s+len-1;
while(p-7>=s)
{
t=0;
for(i=-7;i<=0;i++)
if(p+i>=s) t=t*10+*(p+i)-'0';
p-=8;
num[add++]=t;
}
if(p>=s)
{
t=0;
while(s<=p) t=t*10+*(s++)-'0';
num[add++]=t;
}
while(num.size()>add) num.erase(num.end()-1);
return *this;
}
BigInt operator=(std::string ss)
{
char *s=&ss[0];
f=0;
if(s==0) return BigInt();
if(*s=='-')
{
f=1;
s++;
}
int len=strlen(s),add=0,i,t;
num.resize(len/8+1);
char *p=s+len-1;
while(p>=s)
{
t=0;
for(i=-7;i<=0;i++)
if(p+i>=s) t=t*10+*(p+i)-'0';
p-=8;
num[add++]=t;
}
while(num.size()>add) num.erase(num.end()-1);
return *this;
}
BigInt operator=(int v)
{
f=0;
if(v<0)
{
f=1;
v=-v;
}
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator=(unsigned int v)
{
f=0;
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator=(long long v)
{
f=0;
if(v<0)
{
f=1;
v=-v;
}
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
BigInt operator=(unsigned long long v)
{
f=0;
q.clear();
if(v==0) q.push(0);
else
while(v>0)
{
q.push(v%base);
v/=base;
}
num.resize(q.size());
for(int i=0;q.size()>0;i++)
{
num[i]=q.front();
q.pop();
}
return *this;
}
//====================/
//In-situ operation
BigInt operator++()
{
format();
if(!f)
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
else
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
format();
}
return *this;
}
BigInt operator++(int)
{
format();
BigInt t=*this;
if(!f)
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
else
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
format();
}
return t;
}
BigInt operator--()
{
format();
if(!f)
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
if(num[i-1]<0)
*this=-1;
format();
}
else
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
return *this;
}
BigInt operator--(int)
{
format();
BigInt t=*this;
if(!f)
{
num[0]--;
int i=1;
while(i<num.size()&&num[i-1]<0)
num[i]--,num[i-1]+=base,i++;
if(num[i-1]<0)
*this=-1;
format();
}
else
{
num[0]++;
int i=1;
while(i<num.size()&&num[i-1]>=base)
num[i]++,num[i-1]-=base,i++;
if(num[i-1]>=base)
num.push_back(1),num[i-1]-=base;
}
return t;
}
//=====================/
};
//compare operations
bool operator<(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return a.f>b.f;
if(a.f==0)
{
if(a.num.size()<b.num.size()) return 1;
else if(a.num.size()>b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]<b.num[i]) return 1;
else if(a.num[i]>b.num[i]) return 0;
}
else
{
if(a.num.size()>b.num.size()) return 1;
else if(a.num.size()<b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]>b.num[i]) return 1;
else if(a.num[i]<b.num[i]) return 0;
}
return 0;
}
bool operator==(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return 0;
if(a.num.size()!=b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]!=b.num[i]) return 0;
return 1;
}
bool operator!=(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return 1;
if(a.num.size()!=b.num.size()) return 1;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]!=b.num[i]) return 1;
return 0;
}
bool operator>(BigInt a,BigInt b)
{
a.format();
b.format();
if(a.f!=b.f) return a.f<b.f;
if(a.f==0)
{
if(a.num.size()>b.num.size()) return 1;
else if(a.num.size()<b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]>b.num[i]) return 1;
else if(a.num[i]<b.num[i]) return 0;
}
else
{
if(a.num.size()<b.num.size()) return 1;
else if(a.num.size()>b.num.size()) return 0;
for(int i=a.num.size()-1;i>=0;i--)
if(a.num[i]<b.num[i]) return 1;
else if(a.num[i]>b.num[i]) return 0;
}
return 0;
}
bool operator<=(const BigInt &a,const BigInt &b){return (a<b||a==b);}
bool operator>=(const BigInt &a,const BigInt &b){return (a>b||a==b);}
//=================/
//maths operations
BigInt operator+(BigInt a,BigInt b);
BigInt operator-(BigInt a,BigInt b);
BigInt operator*(BigInt a,BigInt b);
BigInt operator/(BigInt a,BigInt b);
void BigInt_add (BigInt &a,BigInt &b,BigInt &c);
void BigInt_minus (BigInt &a,BigInt &b,BigInt &c);
void BigInt_times (BigInt &a,BigInt &b,BigInt &c);
void BigInt_divide (BigInt &a,BigInt &b,BigInt &c);
void BigInt_add(BigInt &a,BigInt &b,BigInt &c)
{
a.format();
b.format();
c.nAn=(a.nAn==1||b.nAn==1);
if(c.nAn) return;
if(a.f)
{
if(b.f)
{
a.f=b.f=0;
BigInt_add(a,b,c);
a.f=b.f=c.f=1;
return;
}
else
{
a.f=0;
BigInt_minus(b,a,c);
a.f=1;
return;
}
}
else if(b.f)
{
b.f=0;
BigInt_minus(a,b,c);
b.f=1;
return;
}
int t=0,t2=std::max(a.num.size(),b.num.size())+1;
c.num.resize(t2);
memset(&c.num[0],0,t2*4);
for(int i=0;i<t2;i++)
{
if(i<a.num.size()) t+=a.num[i];
if(i<b.num.size()) t+=b.num[i];
c.num[i]=t%BigInt::base;
t/=BigInt::base;
}
c.format();
}
void BigInt_minus(BigInt &a,BigInt &b,BigInt &c)
{
a.format();
b.format();
c.nAn=(a.nAn==1||b.nAn==1);
if(c.nAn) return;
if(a.f)
{
if(b.f)
{
a.f=b.f=0;
BigInt_minus(b,a,c);
a.f=b.f=1;
return;
}
else
{
a.f=0;
BigInt_add(a,b,c);
a.f=c.f=1;
return;
}
}
else if(b.f)
{
b.f=0;
BigInt_add(a,b,c);
b.f=1;
return;
}
if(a<b)
{
BigInt_minus(b,a,c);
c.f=1;
return;
}
c=a;
int z=0,k;
for(int i=0;i<b.num.size();i++)
{
c.num[i]=c.num[i]-b.num[i];
if(c.num[i]<0)
{
c.num[i]+=BigInt::base;
z=1;
}
else z=0;
k=i+1;
while(z&&k<c.num.size())
{
c.num[k]--;
if(c.num[k]<0)
{
z=1;
c.num[k]+BigInt::base;
}
else z=0;
k++;
}
}
c.format();
}
void BigInt_times(BigInt &a,BigInt &b,BigInt &c)
{
a.format();
b.format();
c.nAn=(a.nAn==1||b.nAn==1);
if(c.nAn) return;
c.num.resize(a.num.size()+b.num.size());
memset(&c.num[0],0,(a.num.size()+b.num.size())*4);
int i,j,k,I,J;
long long t;
int *A,*B,*C,As=a.num.size(),Bs=b.num.size();
A=&(a.num[0]);
B=&(b.num[0]);
C=&(c.num[0]);
for(i=0;i<As;i+=CacheSize)
for(j=0;j<Bs;j+=CacheSize)
for(I=i;I<i+CacheSize&&I<As;I++)
for(J=j;J<j+CacheSize&&J<Bs;J++)
{
t=(long long)A[I]*B[J];
t=t+C[I+J];
C[I+J]=t%BigInt::base;
k=I+J+1;
t/=BigInt::base;
while(t>0)
{
t=t+C[k];
C[k++]=t%BigInt::base;
t=t/BigInt::base;
}
}
c.f=(a.f!=b.f);
c.format();
}
void BigInt_divide(BigInt &a,BigInt &b,BigInt &c)
{
BigInt t;
a.format();
b.format();
bool af=a.f,bf=b.f;
a.f=b.f=0;
if(a<b)
{
c=BigInt();
return;
}
c.nAn=(a.nAn==1||b.nAn==1||(b.num.size()==1&&b.num[0]==0));
c.f=0;
if(c.nAn) return;
c.num.resize(a.num.size()-b.num.size()+1,0);
int L,R;
for(int i=c.num.size()-1;i>=0;i--)
{
L=0;
R=a.base-1;
while(L+1<R)
{
c.num[i]=(L+R)/2;
BigInt_times(b,c,t);
if(t>a) R=(L+R)/2;
else L=(L+R)/2;
}
c.num[i]=L;
}
c.format();
a.f=af;
b.f=bf;
c.f=(af!=bf);
}
BigInt operator+(BigInt a,BigInt b)
{
BigInt t;
BigInt_add(a,b,t);
return t;
}
BigInt operator+=(BigInt &a,BigInt b)
{
BigInt t;
BigInt_add(a,b,t);
return a=t;
}
BigInt operator-(BigInt a,BigInt b)
{
BigInt t;
BigInt_minus(a,b,t);
return t;
}
BigInt operator-=(BigInt &a,BigInt b)
{
BigInt t;
BigInt_minus(a,b,t);
return a=t;
}
BigInt operator*(BigInt a,BigInt b)
{
BigInt t;
BigInt_times(a,b,t);
return t;
}
BigInt operator*=(BigInt &a,BigInt b)
{
BigInt t;
BigInt_times(a,b,t);
return a=t;
}
BigInt operator/(BigInt a,BigInt b)
{
BigInt c;
BigInt_divide(a,b,c);
return c;
}
BigInt operator/=(BigInt &a,BigInt b)
{
BigInt c;
BigInt_divide(a,b,c);
return a=c;
}
BigInt operator%(BigInt a,BigInt b)
{
BigInt t1,t2;
BigInt_divide(a,b,t1);
BigInt_times(t1,b,t2);
BigInt_minus(a,t2,t1);
return t1;
}
BigInt operator%=(BigInt &a,BigInt b)
{
BigInt t1,t2;
BigInt_divide(a,b,t1);
BigInt_times(t1,b,t2);
BigInt_minus(a,t2,t1);
return a=t1;
}
void free_pointers()//Releasing temporary memory
{
while(Mems.size()>0)
{
delete[] Mems.front();
Mems.pop();
}
}
//======================/
int read(BigInt &n,FILE *stream=stdin)
{
cache.clear();
char t;
while(!feof(stream))
{
fread(&t,1,1,stream);
if(t=='-'||(t>='0'&&t<='9'))
{
ungetc(t,stream);
break;
}
}
bool flag=0;
while(!feof(stream))
{
fread(&t,1,1,stream);
if(t!='-')
{
ungetc(t,stream);
break;
}
flag=!flag;
}
if(flag) cache.push('-');
while(!feof(stream))
{
fread(&t,1,1,stream);
if(t<'0'||t>'9')
{
ungetc(t,stream);
break;
}
cache.push(t);
}
char *p=new char[cache.size()+1],*tp;
memset(p,0,cache.size()+1);
tp=p;
while(cache.size()>0) *tp++=cache.front(),cache.pop();
n=p;
delete[] p;
}
int write(BigInt n,FILE *stream=stdout)
{
n.format();
if(n.nAn) fprintf(stream,"nan");
else
{
if(n.f) fprintf(stream,"-");
fprintf(stream,"%d",n.num[n.num.size()-1]);
for(int i=n.num.size()-2;i>=0;i--)
fprintf(stream,"%08d",n.num[i]);
}
}
#endif
//stream input and output
#ifdef _GLIBCXX_OSTREAM
std::ostream& operator<<(std::ostream& str,BigInt n)
{
n.format();
if(n.nAn) str<<"nan";
else
str<<n.c_str();
return str;
}
#endif
#ifdef _GLIBCXX_ISTREAM
std::istream& operator>>(std::istream& str,BigInt &n)
{
cache.clear();
while(!str.eof()&&!(str.peek()=='-'||(str.peek()>='0'&&str.peek()<='9')))
str.get();
bool flag=0;
while(!str.eof()&&str.peek()=='-') flag=!flag,str.get();
if(flag) cache.push('-');
while(!str.eof()&&str.peek()>='0'&&str.peek()<='9') cache.push(str.get());
char *p=new char[cache.size()+1],*t;
memset(p,0,cache.size()+1);
t=p;
while(cache.size()>0) *t++=cache.front(),cache.pop();
n=p;
delete[] p;
return str;
}
#endif
using namespace std;
int main()
{
BigInt a,b;
cin>>a>>b;
cout<<a*b<<endl;
return 0;
}
/*
512013230123048014584016540526804565814706519846494321001345794503242112976563432120
5120132301230048014584016540526804565814706519846494321001345794503242112976563432120
*/

18
1.1305.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<bits/stdc++.h>
using namespace std;
int n;
char a[30][3];
void dfs(char x)
{
if(x=='*') return;
cout<<x;
for(int i=1;i<=n;i++)
if(a[i][0]==x) dfs(a[i][1]),dfs(a[i][2]);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
dfs(a[1][0]);
return 0;
}

37
1.1306.cpp Normal file
View File

@ -0,0 +1,37 @@
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL mod=100000000;
LL n,m,a[2][2],c[2][2];
LL gcd(LL a,LL b)
{
int ta,tb;
while(b>0) ta=b,tb=a%b,a=ta,b=tb;
return a;
}
inline void mul(LL a[2][2],LL b[2][2],LL c[2][2])
{
for(int i=0;i<2;i++) for(int j=0;j<2;j++) c[i][j]=(a[i][0]*b[0][j]+a[i][1]*b[1][j])%mod;
}
inline void cp(LL a[2][2],LL b[2][2]) { b[0][0]=a[0][0]; b[0][1]=a[0][1]; b[1][0]=a[1][0]; b[1][1]=a[1][1]; }
inline void ksm(LL a[2][2],LL b,LL c[2][2])
{
c[0][0]=c[1][1]=1; c[0][1]=c[1][0]=0;
LL t[2][2];
for(;b;b>>=1)
{
if(b&1) { mul(c,a,t); cp(t,c); }
mul(a,a,t); cp(t,a);
}
}
int main()
{
scanf("%lld%lld",&n,&m);
LL p=gcd(n,m);
if(p==1||p==2) { puts("1"); return 0; }
a[0][1]=a[1][0]=a[1][1]=1;
ksm(a,p-2,c);
printf("%lld\n",(c[1][0]+c[1][1])%mod);
return 0;
}

19
1.1307.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<cstdio>
int n;
int main()
{
int n,res=0;
scanf("%d",&n);
if(n<0)
{
printf("-");
n=-n;
}
while(n>0)
{
res=res*10+n%10;
n/=10;
}
printf("%d\n",res);
return 0;
}

37
1.1308.cpp Normal file
View File

@ -0,0 +1,37 @@
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
char obj[20],b1[10],s[1000005],b2[10];
int pos=-1,cnt=0;
int main()
{
scanf("%s",obj);
fgets(s,sizeof(s),stdin);
fgets(s,sizeof(s),stdin);
int lena=strlen(obj),lenb=strlen(s);
s[lenb--]=' ';
*(s-1)=' ';
for(int i=0;i<lena;i++) obj[i]=tolower(obj[i]);
for(int i=0;i<lenb;i++) s[i]=tolower(s[i]);
for(int i=0;i+lena<=lenb;i++)
{
bool ok=1;
for(int j=0;j<lena;j++)
if(obj[j]!=s[i+j])
{
ok=0;
break;
}
if(!(s[i-1]==' '&&s[i+lena]==' ')) ok=0;
if(ok)
{
if(pos==-1) pos=i;
cnt++;
}
}
if(pos==-1) printf("-1\n");
else printf("%d %d\n",cnt,pos);
return 0;
}

31
1.1321.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int boy,girl;
char lst,now,shb[128];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
lst='.';
shb['.']='.';
shb['b']='o';
shb['o']='y';
shb['g']='i';
shb['i']='r';
shb['r']='l';
while(now=getchar(),now!=EOF&&now!='\n'&&now!='\r')
{
// printf("read %c expect %c\n",now,shb[lst]);
// if(now=='.') goto nxt;
if((shb[lst]!=now&&lst!='y'&&lst!='l')||((lst=='y'||lst=='l')&&now!='.'))
{
if(now=='b'||now=='o'||now=='y') boy++;
else girl++;
}
nxt: lst=now;
}
printf("%d\n%d\n",boy,girl);
return 0;
}

17
1.1328.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<cstdio>
const int maxn=210;
int n,na,nb,cnta,cntb,a[maxn],b[maxn];
int tb[5][5]={{0,0,1,1,0},{1,0,0,1,0},{0,1,0,0,1},{0,0,1,0,1},{1,1,0,0,0}};
int main()
{
scanf("%d%d%d",&n,&na,&nb);
for(int i=0;i<na;i++) scanf("%d",&a[i]);
for(int i=0;i<nb;i++) scanf("%d",&b[i]);
for(int i=0;i<n;i++)
{
cnta+=tb[a[i%na]][b[i%nb]];
cntb+=tb[b[i%nb]][a[i%na]];
}
printf("%d %d\n",cnta,cntb);
return 0;
}

46
1.1337.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1005;
const double eps=1e-5;
struct OBJ { int x,y,w; };
int n,dx,dy; OBJ a[maxn];
double x,y,step=20000,tx,ty;
void move()
{
double mx=0,my=0,len;
for(int i=1;i<=n;i++)
{
len=sqrt((x-a[i].x)*(x-a[i].x)+(y-a[i].y)*(y-a[i].y));
if(fabs(len)<eps) continue;
mx+=a[i].w*(a[i].x-x)/len;
my+=a[i].w*(a[i].y-y)/len;
}
len=sqrt(mx*mx+my*my);
x+=step*mx/len;
y+=step*my/len;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
while(step>=eps)
{
tx=x,ty=y;
move();
if(fabs(tx-x)<eps&&fabs(ty-y)<eps) break;
if(dx!=(x>tx)||dy!=(y>ty))
{
dx=x>tx;
dy=y>ty;
step=step*0.5;
}
// printf(">>> %.3lf %.3lf\n",x,y);
}
printf("%.3lf %.3lf\n",x,y);
return 0;
}

60
1.1347.cpp Normal file
View File

@ -0,0 +1,60 @@
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<stack>
using namespace std;
int n,m;
struct Edge { int v,id; };
vector<Edge> G[30];
inline void AddEdge(int u,int v,int id) { G[u].push_back((Edge){v,id}); }
inline void solve(int id)
{
static int in[30],res[30];
memset(in,0,sizeof(in));
for(int i=1;i<=n;i++) for(Edge it:G[i]) if(it.id<=id) in[it.v]++;
stack<int> stk;
for(int i=1;i<=n;i++) if(!in[i]) stk.push(i);
bool unsure=0; int cnt=0;
while(stk.size())
{
unsure|=(stk.size()>=2);
int u=res[cnt++]=stk.top(); stk.pop();
for(Edge it:G[u]) if(it.id<=id)
{
in[it.v]--;
if(!in[it.v]) stk.push(it.v);
}
}
for(int i=1;i<=n;i++) if(in[i])
{
printf("Inconsistency found after %d relations.\n",id);
exit(0);
}
if(unsure) return;
printf("Sorted sequence determined after %d relations: ",id);
for(int i=0;i<cnt;i++) putchar(res[i]-1+'A');
puts(".");
exit(0);
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
assert(m>=1);
assert(m<=n*(n-1));
for(int i=0;i<m;i++)
{
char s[10]; scanf("%s",s);
int u=s[0]-'A'+1,v=s[2]-'A'+1;
if(s[1]=='>') swap(u,v);
AddEdge(u,v,i+1);
}
for(int i=1;i<=m;i++) solve(i);
puts("Sorted sequence cannot be determined.");
return 0;
}

43
1.1351.cpp Normal file
View File

@ -0,0 +1,43 @@
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=200005;
const int mod=10007;
struct Edge { int v; Edge *next; };
Edge mem[maxn*2],*G[maxn],*ecnt=mem;
inline void AddEdge(int u,int v) { ecnt->v=v; ecnt->next=G[u]; G[u]=ecnt++; }
int n,mx,tot,a[maxn],m1[maxn],m2[maxn],sum[maxn];
void dfs(int u,int fa)
{
for(Edge *it=G[u];it;it=it->next)
{
int v=it->v;
if(v==fa) continue;
dfs(v,u);
if(a[v]>=m1[u]) { m2[u]=m1[u]; m1[u]=a[v]; }
else if(a[v]>=m2[u]) m2[u]=a[v];
mx=max(mx,a[u]*m1[v]);
tot=(tot+sum[u]*a[v])%mod;
sum[u]=(sum[u]+a[v])%mod;
tot=(tot+a[u]*sum[v])%mod;
}
mx=max(mx,m1[u]*m2[u]);
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=0;i<n-1;i++)
{
int u,v; scanf("%d%d",&u,&v);
AddEdge(u,v); AddEdge(v,u);
}
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
dfs(1,-1);
printf("%d %d\n",mx,tot*2%mod);
return 0;
}

29
1.1373.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=805;
const int mod=1e9+7;
int n,m,p,a[maxn][maxn],f[maxn][maxn][20][2];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d%d",&n,&m,&p); p++;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) f[i][j][a[i][j]%p][0]=1;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=0;k<p;k++)
{
int v=f[i][j][k][0];
(f[i+1][j][((k-a[i+1][j])%p+p)%p][1]+=v)%=mod;
(f[i][j+1][((k-a[i][j+1])%p+p)%p][1]+=v)%=mod;
v=f[i][j][k][1];
(f[i+1][j][(k+a[i+1][j])%p][0]+=v)%=mod;
(f[i][j+1][(k+a[i][j+1])%p][0]+=v)%=mod;
}
int res=0;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) (res+=f[i][j][0][1])%=mod;
printf("%d\n",res);
return 0;
}

101
1.1379.cpp Normal file
View File

@ -0,0 +1,101 @@
#include<iostream>
#include<algorithm>
//#include"conio.h"
using namespace std;
long long hashtable[3628800];
inline void set_hash(long long n)
{
static long long p;
p=(n*1000009)%3628800;
while(hashtable[p]>0&&hashtable[p]!=n) p++;
hashtable[p]=n;
}
inline bool get_hash(long long n)
{
static long long p;
p=(n*1000009)%3628800;
while(hashtable[p]>0)
{
if(hashtable[p]==n) return 1;
p++;
}
return 0;
}
struct node
{
long long state;
int step;
};
long long s,e;
node que[362885];
int head,tail;
char arr[10];
int d[]={-3,-1,1,3};
int main()
{
cin>>s;
e=123804765;
// cout<<"s= "<<s<<" e= "<<e<<endl;
set_hash(s);
que[tail++].state=s;
node t;
int i,pos,j;
long long tt;
while(head<tail)
{
t=que[head];
if(t.state==e)
{
cout<<que[head].step<<endl;
return 0;
}
for(i=8;i>=0;i--)
{
arr[i]=t.state%10;
t.state/=10;
if(arr[i]==0) pos=i;
}
for(i=0;i<4;i++)
{
switch(d[i])
{
case -3:
if(pos/3>0) goto addr1;
else goto addr2;
case -1:
if(pos%3>0) goto addr1;
else goto addr2;
case 1:
if(pos%3<2) goto addr1;
else goto addr2;
case 3:
if(pos/3<2) goto addr1;
else goto addr2;
}
addr1:
swap(arr[pos+d[i]],arr[pos]);
tt=0;
for(j=0;j<9;j++)
tt=tt*10+arr[j];
if(!get_hash(tt))
{
set_hash(tt);
// cout<<"insert "<<tt<<endl;
// getch();
que[tail].state=tt;
que[tail].step=t.step+1;
tail++;
}
swap(arr[pos+d[i]],arr[pos]);
addr2:
continue;
}
head++;
}
cout<<"impossible"<<endl;
return 0;
}
/*
283104765
123804765
*/

21
1.1420.cpp Normal file
View File

@ -0,0 +1,21 @@
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x,res,now,v;
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&x);
res=now=1; v=x;
for(int i=2;i<=n;i++)
{
scanf("%d",&x);
if(x==v+1) { v=x; now++; }
else { v=x; now=1; }
res=max(res,now);
}
printf("%d\n",res);
return 0;
}

9
1.1421.cpp Normal file
View File

@ -0,0 +1,9 @@
#include<cstdio>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
int y=a*10+b;
printf("%d\n",y/19);
return 0;
}

13
1.1422.cpp Normal file
View File

@ -0,0 +1,13 @@
#include<cstdio>
int main()
{
double n;
scanf("%lf",&n);
double res;
if(n<=150) res=n*0.4463;
else if(n<=400) res=150*0.4463+(n-150)*0.4663;
else res=150*0.4463+250*0.4663+(n-400)*0.5663;
printf("%.1lf\n",res);
return 0;
}
//267

15
1.1423.cpp Normal file
View File

@ -0,0 +1,15 @@
#include<cstdio>
int main()
{
int cnt=0;
double step=2.0,in;
scanf("%lf",&in);
while(in>0)
{
cnt++;
in-=step;
step*=0.98;
}
printf("%d\n",cnt);
return 0;
}

10
1.1425.cpp Normal file
View File

@ -0,0 +1,10 @@
#include<cstdio>
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
int f=(a-c-1)*60+b+60-d;
printf("%d %d\n",-f/60,-f%60);
return 0;
}
//12 50 19 10

11
1.1426.cpp Normal file
View File

@ -0,0 +1,11 @@
#include<cstdio>
#include<cmath>
int main()
{
double s,x,tEnter,tExit;
scanf("%lf%lf",&s,&x);
tEnter=log(1-0.02*(s-x)/7)/log(0.98);
tExit=log(1-0.02*(s+x)/7)/log(0.98);
printf("%c",tExit-tEnter>=1?'y':'n');
return 0;
}

12
1.1427.cpp Normal file
View File

@ -0,0 +1,12 @@
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int x; stack<int> stk;
int main()
{
while(cin>>x,x) stk.push(x);
while(stk.size()) { printf("%d ",stk.top()); stk.pop(); }
puts("");
return 0;
}

19
1.1428.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<iostream>
using namespace std;
int n,a[105];
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
int tot=0;
for(int j=1;j<i;j++) tot+=(a[j]<a[i]);
cout<<tot<<' ';
}
cout<<endl;
return 0;
}

47
1.1436.cpp Normal file
View File

@ -0,0 +1,47 @@
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int oo=0x3f3f3f3f;
int n,a[20][20],s[20][20],vis[20][20][20][20][20];
int f[20][20][20][20][20],tot;
int dp(int R1,int C1,int R2,int C2,int tot)
{
int &res=f[R1][C1][R2][C2][tot];
if(vis[R1][C1][R2][C2][tot]) return res;
vis[R1][C1][R2][C2][tot]=1;
if(tot>(R2-R1+1)*(C2-C1+1)) return res=oo;
if(tot==1)
{
double v=s[R2][C2]-s[R2][C1-1]-s[R1-1][C2]+s[R1-1][C1-1];
return res=v*v;
}
res=oo;
for(int R=R1;R<R2;R++)
{
int t=1;
res=min(res,dp(R1,C1,R,C2,t)+dp(R+1,C1,R2,C2,tot-t));
t=tot-1;
res=min(res,dp(R1,C1,R,C2,t)+dp(R+1,C1,R2,C2,tot-t));
}
for(int C=C1;C<C2;C++)
{
int t=1;
res=min(res,dp(R1,C1,R2,C,t)+dp(R1,C+1,R2,C2,tot-t));
t=tot-1;
res=min(res,dp(R1,C1,R2,C,t)+dp(R1,C+1,R2,C2,tot-t));
}
return res;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=1;i<=8;i++) for(int j=1;j<=8;j++) { scanf("%d",&a[i][j]); tot+=a[i][j]; }
for(int i=1;i<=8;i++) for(int j=1;j<=8;j++) s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
printf("%d\n",dp(1,1,8,8,n));
return 0;
}

27
1.1437.cpp Normal file
View File

@ -0,0 +1,27 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=55;
int n,m,a[maxn][maxn],dp[maxn][maxn][1300],res;
inline void upd(int &a,const int &b) { b>a?a=b:0; }
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) for(int j=1;j<=n-i+1;j++) scanf("%d",&a[i][j]);
memset(dp,-127,sizeof(dp));
dp[n+1][0][0]=0;
for(int c=n;c>=1;c--)
for(int r=0,s=0;r<=n-c+1;r++,s+=a[r][c])
for(int k=r;k<=m;k++)
for(int l=max(0,r-1);l<=n-c;l++)
{
upd(dp[c][r][k],dp[c+1][l][k-r]+s);
upd(res,dp[c][r][k]);
}
printf("%d\n",res);
return 0;
}

28
1.1439.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;
const int oo=1e9+7;
int n,x;
int idx[maxn],dp[maxn];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&x),idx[x]=i+1;
fill(dp,dp+n+2,oo);
dp[0]=0;
for(int i=0;i<n;i++)
{
scanf("%d",&x); x=idx[x];
*lower_bound(dp,dp+n+2,x)=x;
}
printf("%d\n",lower_bound(dp,dp+n+2,oo)-dp-1);
return 0;
}
/*
5
3 2 1 4 5
1 2 3 4 5
3 2 1 4 5
*/

38
1.1443.cpp Normal file
View File

@ -0,0 +1,38 @@
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=405;
const int dr[]={-2,-2,-1,1,2,2,1,-1};
const int dc[]={-1,1,2,2,1,-1,-2,-2};
struct node { int r,c; };
int dis[maxn][maxn];
int n,m,r,c;
int main()
{
scanf("%d%d%d%d",&n,&m,&r,&c);
memset(dis,-1,sizeof(dis));
queue<node> que;
que.push((node){r,c});
dis[r][c]=0;
while(que.size())
{
node u=que.front(); que.pop();
for(int i=0;i<8;i++)
{
node v=(node){u.r+dr[i],u.c+dc[i]};
if(v.r>=1&&v.r<=n&&v.c>=1&&v.c<=m&&dis[v.r][v.c]==-1)
{
dis[v.r][v.c]=dis[u.r][u.c]+1;
que.push(v);
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) printf("%-5d",dis[i][j]);
printf("\n");
}
return 0;
}

18
1.1449.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<cstdio>
typedef long long LL;
LL stk[1005]; int top;
LL now; char ch;
int main()
{
while(ch=getchar(),ch!='@')
{
if(ch>='0'&&ch<='9') now=now*10+ch-'0';
else if(ch=='.') stk[top++]=now,now=0;
else if(ch=='+') stk[top-2]+=stk[top-1],--top;
else if(ch=='-') stk[top-2]-=stk[top-1],--top;
else if(ch=='*') stk[top-2]*=stk[top-1],--top;
else if(ch=='/') stk[top-2]/=stk[top-1],--top;
}
printf("%lld\n",stk[0]);
return 0;
}

30
1.1454.cpp Normal file
View File

@ -0,0 +1,30 @@
#include<iostream>
using namespace std;
int y,x;
char mp[105][105];
int dx[12]={0,0,1,-1,1,-1,-1,1,0,0,2,-2};//各个位置
int dy[12]={1,-1,0,0,1,-1,1,-1,2,-2,0,0};
void dfs(int xs,int ys)
{
if(mp[xs][ys]!='#') return;
mp[xs][ys]=0;
for(int i=0;i<12;i++)
dfs(xs+dx[i],ys+dy[i]);
}
int main()
{
cin>>y>>x;
for(int i=2;i<=y+1;i++)
for(int j=2;j<=x+1;j++)
cin>>mp[j][i];
int cnt=0;
for(int i=2;i<=y+1;i++)
for(int j=2;j<=x+1;j++)
if(mp[j][i]=='#')
{
cnt++;
dfs(j,i);
}
cout<<cnt<<endl;
return 0;
}

44
1.1463.cpp Normal file
View File

@ -0,0 +1,44 @@
#include<cstdio>
typedef long long LL;
inline int K(int x)
{
int k=0; for(;(1<<k)<=x;++k);
return k;
}
LL n,res,mxgs;
const int p[16]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int limit_p[16],p1;
void dfs(LL i,LL gs,LL num,LL mxq)
{
if(num>n) return;
if(i>1) limit_p[i]=p1/(K(p[i])-1)+1;//ceil((p1+1)/(K(p[i])-1))
LL val=num*p[i],q=1,ngs=gs;
while(q<limit_p[i]&&q<=mxq&&val<=n)
{
ngs=gs*(q+1);
if(ngs>mxgs) mxgs=ngs,res=val;
if(ngs==mxgs&&val<res) res=val;
if(i==1) p1=q;
dfs(i+1,ngs,val,q);
val*=p[i],++q;
}
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%lld",&n);
if(n==1) { printf("1\n"); return 0; }
res=mxgs=1;
LL x=1,t=0;
for(int i=1;i<16&&x<=n;++i) x*=p[i],t=i;
t=K(p[t])*2-1;
limit_p[1]=t;
dfs(1,1,1,20);
printf("%lld\n",res);
return 0;
}

23
1.1478.cpp Normal file
View File

@ -0,0 +1,23 @@
#include<cstdio>
#include<algorithm>
using namespace std;
struct node { int h,w; };
inline bool operator<(const node &a,const node &b) { return a.w<b.w; }
int n,s,h,x;
node ap[5005];
int main()
{
scanf("%d%d",&n,&s);
scanf("%d%d",&h,&x); h+=x;
for(int i=0;i<n;i++) scanf("%d%d",&ap[i].h,&ap[i].w);
sort(ap,ap+n);
int res=0;
for(int i=0;i<n;i++)
if(s>=ap[i].w&&h>=ap[i].h)
{
s-=ap[i].w;
res++;
}
printf("%d\n",res);
return 0;
}

58
1.1494.cpp Normal file
View File

@ -0,0 +1,58 @@
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
struct Query
{
int l,r,id;
LL len;
}b[60000];
int a[60000],bl[60000],n,m,blo,cnt[60000];
LL A[60000],B[60000],tot;
inline bool cmp(const Query &a,const Query &b)
{
if(bl[a.l]<bl[b.l]) return 1;
if(bl[a.l]>bl[b.l]) return 0;
if(bl[a.l]&1) return a.r<b.r;
return a.r>b.r;
}
inline void add(int x) { tot+=((cnt[x]<<1)|1); cnt[x]++; }
inline void del(int x) { tot+=1-(cnt[x]<<1); cnt[x]--; }
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
int blo=n/sqrt(m*2/3);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&b[i].l,&b[i].r);
b[i].len=b[i].r-b[i].l+1; b[i].id=i; B[i]=1; bl[i]=(i-1)/blo+1;
}
sort(b+1,b+m+1,cmp);
int l=b[1].l,r=b[1].r;
for(int i=l;i<=r;i++) add(a[i]);
LL fz,fm,g;
if(tot!=b[1].len)
{
fz=tot-b[1].len; fm=b[1].len*(b[1].len-1); g=__gcd(fz,fm);
A[b[1].id]=fz/g; B[b[1].id]=fm/g;
}
for(int i=2;i<=m;i++)
{
while(l<b[i].l) del(a[l++]);
while(l>b[i].l) add(a[--l]);
while(r>b[i].r) del(a[r--]);
while(r<b[i].r) add(a[++r]);
if(b[i].len!=tot)
{
fz=tot-b[i].len; fm=b[i].len*(b[i].len-1);
g=__gcd(fz,fm); A[b[i].id]=fz/g; B[b[i].id]=fm/g;
}
}
for(int i=1;i<=m;i++) printf("%lld/%lld\n",A[i],B[i]);
return 0;
}

48
1.1514.cpp Normal file
View File

@ -0,0 +1,48 @@
#ifdef wxp
#include"all.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
const int maxn=505;
const int dr[]={-1,1,0,0},dc[]={0,0,-1,1};
int n,m,a[maxn][maxn];
int vis[maxn][maxn],L[maxn][maxn],R[maxn][maxn];
#define nr (r+dr[i])
#define nc (c+dc[i])
void dfs(int r,int c)
{
vis[r][c]=true;
for(int i=0;i<4;i++)
{
if(nr<1||nr>n||nc<1||nc>m) continue;
if(a[nr][nc]>=a[r][c]) continue;
if(!vis[nr][nc]) dfs(nr,nc);
L[r][c]=min(L[r][c],L[nr][nc]);
R[r][c]=max(R[r][c],R[nr][nc]);
}
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
memset(L,0x3f,sizeof(L));
for(int i=1;i<=m;i++) L[n][i]=R[n][i]=i;
for(int i=1;i<=m;i++) if(!vis[1][i]) dfs(1,i);
int cnt=0,now=1;
for(int i=1;i<=m;i++) cnt+=!vis[n][i];
if(cnt) { printf("0\n%d\n",cnt); return 0; }
// for(int i=1;i<=m;i++) printf("L[%d]=%d R[%d]=%d\n",i,L[1][i],i,R[1][i]);
while(now<=m)
{
int maxr=0;
for(int i=1;i<=m;i++) if(L[1][i]<=now) maxr=max(maxr,R[1][i]);
cnt++;
now=maxr+1;
}
printf("1\n%d\n",cnt);
return 0;
}

47
1.1525.cpp Normal file
View File

@ -0,0 +1,47 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=20005;
const int maxm=100005;
struct ZF { int a,b,c; };
inline bool operator<(const ZF &x,const ZF &y) { return x.c>y.c; }
int n,m,fa[maxn*2];
ZF zf[maxm];
inline int ff(int u)
{
int a=u,b;
while(u!=fa[u]) u=fa[u];
while(a!=u)
{
b=fa[a];
fa[a]=u;
a=b;
}
return u;
}
inline void merge(int a,int b)
{
a=ff(a); b=ff(b);
fa[a]=b;
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d%d%d",&zf[i].a,&zf[i].b,&zf[i].c);
sort(zf+1,zf+m+1);
for(int i=1;i<=n*2;i++) fa[i]=i;
for(int i=1;i<=m;i++)
{
int ax=zf[i].a*2,ay=zf[i].a*2-1;
int bx=zf[i].b*2,by=zf[i].b*2-1;
merge(ax,by);
merge(ay,bx);
if(ff(ax)==ff(ay)||ff(bx)==ff(by)) { printf("%d\n",zf[i].c); return 0; }
}
puts("0");
return 0;
}

Some files were not shown because too many files have changed in this diff Show More