毒瘤场.....
A题:,真码农题,直接干爆,枚举,注意越界问题,wa37的看这组数据1 10 1 5 2 2,应该是no
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pii pair<int,int> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-12; const int N=1000000+10,maxn=2000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; int main() { int n,m,i,j,a,b; scanf("%d%d%d%d%d%d",&n,&m,&i,&j,&a,&b); int ans1=-1,ans2=-1,ans3=-1,ans4=-1; if(abs(i-1)%a==0&&abs(j-1)%b==0&&abs(i-1)/a%2==abs(j-1)/b%2) { if(abs(j-1)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-1)/a==0)ans1=max(abs(i-1)/a,abs(j-1)/b); else if(abs(i-1)/a!=0&&(1<=j-b||j+b<=m)&&abs(j-1)/b!=0)ans1=max(abs(i-1)/a,abs(j-1)/b); else if(abs(j-1)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-1)/a!=0&&(1<=j-b||j+b<=m))ans1=max(abs(i-1)/a,abs(j-1)/b); else if(abs(i-1)/a==0&&abs(j-1)/b==0)ans1=max(abs(i-1)/a,abs(j-1)/b); } if(abs(i-1)%a==0&&abs(j-m)%b==0&&abs(i-1)/a%2==abs(j-m)/b%2) { if(abs(j-m)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-1)/a==0)ans2=max(abs(i-1)/a,abs(j-m)/b); else if(abs(i-1)/a!=0&&(1<=j-b||j+b<=m)&&abs(j-m)/b!=0)ans2=max(abs(i-1)/a,abs(j-m)/b); else if(abs(j-m)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-1)/a!=0&&(1<=j-b||j+b<=m))ans2=max(abs(i-1)/a,abs(j-m)/b); else if(abs(i-1)/a==0&&abs(j-m)/b==0)ans2=max(abs(i-1)/a,abs(j-m)/b); } if(abs(i-n)%a==0&&abs(j-1)%b==0&&abs(i-n)/a%2==abs(j-1)/b%2) { if(abs(j-1)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-n)/a==0)ans3=max(abs(i-n)/a,abs(j-1)/b); else if(abs(i-n)/a!=0&&(1<=j-b||j+b<=m)&&abs(j-1)/b!=0)ans3=max(abs(i-n)/a,abs(j-1)/b); else if(abs(j-1)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-n)/a!=0&&(1<=j-b||j+b<=m))ans3=max(abs(i-n)/a,abs(j-1)/b); else if(abs(i-n)/a==0&&abs(j-1)/b==0)ans3=max(abs(i-n)/a,abs(j-1)/b); } if(abs(i-n)%a==0&&abs(j-m)%b==0&&abs(i-n)/a%2==abs(j-m)/b%2) { if(abs(j-m)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-n)/a==0)ans4=max(abs(i-n)/a,abs(j-m)/b); else if(abs(i-n)/a!=0&&(1<=j-b||j+b<=m)&&abs(j-m)/b!=0)ans4=max(abs(i-n)/a,abs(j-m)/b); else if(abs(j-m)/b!=0&&(1<=i-a||i+a<=n)&&abs(i-n)/a!=0&&(1<=j-b||j+b<=m))ans4=max(abs(i-1)/a,abs(j-m)/b); else if(abs(i-n)/a==0&&abs(j-m)/b==0)ans4=max(abs(i-n)/a,abs(j-m)/b); } // printf("%d %d\n",abs(i-n)/a%2,abs(j-m)/b%2); if(ans1!=-1||ans2!=-1||ans3!=-1||ans4!=-1) { int ans=100000000; if(ans1!=-1)ans=min(ans,ans1); if(ans2!=-1)ans=min(ans,ans2); if(ans3!=-1)ans=min(ans,ans3); if(ans4!=-1)ans=min(ans,ans4); printf("%d\n",ans); } else puts("Poor Inna and pony!"); return 0; } /******************** 3 5 2 2 1 3 ********************/
B题:日常贪心不会写,xjb写成了dp,还写搓了
题意:找相邻的合成9,要求组出最多的9的方案数;
直接贪心的扫到最远处,类似于72727这样的,然后乘到答案上
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pii pair<int,int> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-12; const int N=100000+10,maxn=2000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; char s[N]; int main() { scanf("%s",s+1); int sz=strlen(s+1); ll ans=1,p=1; for(int i=2;i<=sz;i++) { if(s[i]-‘0‘+s[i-1]-‘0‘==9)p++; else { // printf("%d\n",p); if(p!=1&&p%2==1)ans*=(p+1)/2; p=1; } } // printf("%d\n",p); if(p!=1&&p%2==1)ans*=(p+1)/2; printf("%lld\n",ans); return 0; } /******************** ********************/
C:有nm的矩阵,找最长的dima,转化成dag上的dp,从d开始dp,然后找能走的最远距离除4就是答案,注意这题要判环,用一个vis标记,-1表示当前正在访问的这一条路,1表示访问过了,0表示没有访问过,如果访问到了一个正在访问的地方,那么就是有环
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pii pair<int,int> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-9; const int N=1000+10,maxn=2000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; char s[N][N]; int dp[N*N]; int n,m; int vis[N*N]; vector<int>v[N*N]; int dfs(int u) { // printf("%d\n",u); if(dp[u]!=-1)return dp[u]; dp[u]=1;vis[u]=-1; for(int i=0;i<v[u].size();i++) { int x=v[u][i]; if(vis[x]<0) { puts("Poor Inna!"); exit(0); } dp[u]=max(dp[u],dfs(x)+1); } vis[u]=1; return dp[u]; } int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%s",s[i]); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(s[i][j]==‘D‘) { if(i+1<n&&s[i+1][j]==‘I‘)v[i*m+j].pb((i+1)*m+j); if(i-1>=0&&s[i-1][j]==‘I‘)v[i*m+j].pb((i-1)*m+j); if(j+1<m&&s[i][j+1]==‘I‘)v[i*m+j].pb(i*m+j+1); if(j-1>=0&&s[i][j-1]==‘I‘)v[i*m+j].pb(i*m+j-1); } else if(s[i][j]==‘I‘) { if(i+1<n&&s[i+1][j]==‘M‘)v[i*m+j].pb((i+1)*m+j); if(i-1>=0&&s[i-1][j]==‘M‘)v[i*m+j].pb((i-1)*m+j); if(j+1<m&&s[i][j+1]==‘M‘)v[i*m+j].pb(i*m+j+1); if(j-1>=0&&s[i][j-1]==‘M‘)v[i*m+j].pb(i*m+j-1); } else if(s[i][j]==‘M‘) { if(i+1<n&&s[i+1][j]==‘A‘)v[i*m+j].pb((i+1)*m+j); if(i-1>=0&&s[i-1][j]==‘A‘)v[i*m+j].pb((i-1)*m+j); if(j+1<m&&s[i][j+1]==‘A‘)v[i*m+j].pb(i*m+j+1); if(j-1>=0&&s[i][j-1]==‘A‘)v[i*m+j].pb(i*m+j-1); } else if(s[i][j]==‘A‘) { if(i+1<n&&s[i+1][j]==‘D‘)v[i*m+j].pb((i+1)*m+j); if(i-1>=0&&s[i-1][j]==‘D‘)v[i*m+j].pb((i-1)*m+j); if(j+1<m&&s[i][j+1]==‘D‘)v[i*m+j].pb(i*m+j+1); if(j-1>=0&&s[i][j-1]==‘D‘)v[i*m+j].pb(i*m+j-1); } } } memset(dp,-1,sizeof dp); int ans=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) { int res=dfs(i*m+j); if(s[i][j]==‘D‘) ans=max(ans,res/4); } if(ans==0)puts("Poor Dima!"); else printf("%d\n",ans); return 0; } /******************** ********************/
D:有一个队列,三种操作,1代表插入1,0代表插入0,-1代表删除下标为a[i]的数,最后输出队列里的数即可
套路题,树状数组维护前缀和,每次删点就在树状数组里的对应地方删点,然后二分找对应在树状数组里的下标
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pii pair<int,int> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-9; const int N=1000000+10,maxn=2000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; int sum[N],a[N],ans[N]; int cnt; void add(int i,int v) { while(i<N) { sum[i]+=v; i+=i&(-i); } } int query(int i) { int ans=0; while(i>0) { ans+=sum[i]; i-=i&(-i); } return ans; } int change(int x) { int l=0,r=cnt+1; while(l<r-1) { int m=(l+r)>>1; // printf("%d %d\n",m,query(m)); if(query(m)<x)l=m; else r=m; } if(query(r)<x)return -1; return r; } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++)scanf("%d",&a[i]); cnt=1; for(int i=0;i<n;i++) { int x; scanf("%d",&x); if(x==-1) { vector<int>v; for(int j=1;j<=m;j++) { int pos=change(a[j]); // printf("###%d!!!\n",pos); if(pos==-1)break; v.pb(pos); } for(int i=0;i<v.size();i++) add(v[i],-1); } else { add(cnt,1); ans[cnt++]=x; } } // printf("%d\n",change(1)); if(change(1)==-1)return 0*puts("Poor stack!"); for(int i=1;;i++) { int pos=change(i); if(pos==-1)break; printf("%d",ans[pos]); } return 0; } /******************** ********************/