CodeForces 758C Unfair Poll(模拟)

      CodeForces 758C  Unfair Poll(模拟)

    模拟题,需要注意很多细节,我写的代码有点麻烦,弄个图很直观    
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h> 
#include <string>
#include <vector>
#include <queue> 
#include <stack> 
#include <set>
#include <map>
using namespace std;
const long long INF=1000000000000000003;
long long a[105][105];
int main(void)
{int n,m,x,y;long long k;long long Max=-1,Min=INF;scanf("%d%d%lld%d%d",&n,&m,&k,&x,&y);memset(a,0,sizeof(a));//把k比n*m小的情况单独列了出来 if(k<n*m){int flag=0;int count=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){count++;if(count>k){flag=1;break;}a[i][j]=1;   }if(flag) break;}printf("1 0 %lld\n",a[x][y]);return 0;   }//当n为一的情况 if(n==1){long long t=k/m;long long tt=k%m;long long q;if(y>tt) q=t;else q=t+1;if(tt)printf("%lld %lld %lld\n",t+1,t,q);elseprintf("%lld %lld %lld\n",t,t,t); //正好问了整数次 ,因为忽略了这种情况wa了好几次  return 0; } //处理一 for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=1;       //处理二       long long b=((k-(n*m))/((n-1)*m));long long c=((k-(n*m))%((n-1)*m));long long xx=b/2;long long ss=b-xx;for(int i=1;i<=n-1;i++)for(int j=1;j<=m;j++)a[i][j]+=ss;for(int i=2;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]+=xx;//处理三,注意方向	    if(b%2==0){long long count=0;int flag=0;	for(int i=n-1;i>=1;i--){for(int j=1;j<=m;j++){count++;if(count>c){flag=1;break;}a[i][j]++;}if(flag) break;}}else if(b%2==1){long long  count=0;int flag=0;	for(int i=2;i<=n;i++){for(int j=1;j<=m;j++){count++;if(count>c){flag=1;break;}a[i][j]++;}if(flag) break;}}//找最大最小 for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){if(a[i][j]>Max) Max=a[i][j];if(a[i][j]<Min) Min=a[i][j];}printf("%lld %lld %lld\n",Max,Min,a[x][y]);return 0;   
}


CodeForces 758C Unfair Poll(模拟)

      CodeForces 758C  Unfair Poll(模拟)

    模拟题,需要注意很多细节,我写的代码有点麻烦,弄个图很直观    
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h> 
#include <string>
#include <vector>
#include <queue> 
#include <stack> 
#include <set>
#include <map>
using namespace std;
const long long INF=1000000000000000003;
long long a[105][105];
int main(void)
{int n,m,x,y;long long k;long long Max=-1,Min=INF;scanf("%d%d%lld%d%d",&n,&m,&k,&x,&y);memset(a,0,sizeof(a));//把k比n*m小的情况单独列了出来 if(k<n*m){int flag=0;int count=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){count++;if(count>k){flag=1;break;}a[i][j]=1;   }if(flag) break;}printf("1 0 %lld\n",a[x][y]);return 0;   }//当n为一的情况 if(n==1){long long t=k/m;long long tt=k%m;long long q;if(y>tt) q=t;else q=t+1;if(tt)printf("%lld %lld %lld\n",t+1,t,q);elseprintf("%lld %lld %lld\n",t,t,t); //正好问了整数次 ,因为忽略了这种情况wa了好几次  return 0; } //处理一 for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=1;       //处理二       long long b=((k-(n*m))/((n-1)*m));long long c=((k-(n*m))%((n-1)*m));long long xx=b/2;long long ss=b-xx;for(int i=1;i<=n-1;i++)for(int j=1;j<=m;j++)a[i][j]+=ss;for(int i=2;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]+=xx;//处理三,注意方向	    if(b%2==0){long long count=0;int flag=0;	for(int i=n-1;i>=1;i--){for(int j=1;j<=m;j++){count++;if(count>c){flag=1;break;}a[i][j]++;}if(flag) break;}}else if(b%2==1){long long  count=0;int flag=0;	for(int i=2;i<=n;i++){for(int j=1;j<=m;j++){count++;if(count>c){flag=1;break;}a[i][j]++;}if(flag) break;}}//找最大最小 for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){if(a[i][j]>Max) Max=a[i][j];if(a[i][j]<Min) Min=a[i][j];}printf("%lld %lld %lld\n",Max,Min,a[x][y]);return 0;   
}