牛客小白月赛59-C+D
C+D两道大水题。。。C纯粹细节问题,暴力可过;D做过,遍历统计即可
C 输出练习
题目链接:https://ac.nowcoder.com/acm/contest/43844/C
呜呜呜,纯纯大水题,打的时候没看出来,其实暴力蛮快的,同时就是注意细节问题哈,因为这里最好单独判断k=0和k=1的情况,剩下的k一种情况。多说无益,上代码!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<cmath> #include<map> #include<vector> #define ll long long #define ull unsigned long long #define mem(x,y) memset(x,y,sizeof(x)) //#define int long long inline ll read() { ll x=0,f=1; char ch= getchar (); while (ch< '0' ||ch> '9' ){ if (ch== '-' ) f=-1;ch= getchar ();} while (ch>= '0' &&ch<= '9' ){x=x*10+ch-48;ch= getchar ();} return x*f; } using namespace std; const int maxm=2e5+5,inf=0x3f3f3f3f; ll l,r,k; void solve(){ bool flag= true ; cin>>l>>r>>k; if (k==0){ if (l==0&&r==0){ cout<<0<<endl; } else if (l==0&&r>=1){ cout<< "0 1" <<endl; } else if (l==1) cout<< "1\n" ; else cout<< "None.\n" ; return ; } else if (k==1){ if (l<=1&&r>=1){ cout<<1<<endl; } else cout<< "None.\n" ; return ; } //k>=2 ll now=1; while (now<=r){ if (now>=l){ cout<<now<< ' ' ; flag= false ; } if (now<=r/k) //此处用来判读是否会爆long long now*=k; //除法的思想学一学 else break ; // } if (flag) cout<< "None." ; cout<<endl; return ; } signed main(){ // ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int _=1; cin>>_; while (_--){ solve(); } return 0; } |
D 国际象棋
题目链接:https://ac.nowcoder.com/acm/contest/43844/D
D题做过其实。。。只能说打的时候手不够快,脑子不够灵光。
打的时候错误原因是算法假了,我仅仅判断当前放入点的八个方向,以当前点为起点,这样是存在问题的。事实上我们需要在每放入一个棋子后判断整个棋盘的k子连珠状态,但是那样的话容易超时,而且也是一种赘余的操作。因为放入的棋子仅仅会改变当前位置的八个方向的k子连珠的成功性,所以只需要判断以当前落入子的位置作为k子的一部分,在8个方向遍历,之后判断4个大方向的最长连珠能否超过k即可。
当然,遍历8个方向的时候取个负就可以变成遍历4个正负方向。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<cmath> #include<map> #include<vector> #define ll long long #define ull unsigned long long #define mem(x,y) memset(x,y,sizeof(x)) //#define int long long inline ll read() { ll x=0,f=1; char ch= getchar (); while (ch< '0' ||ch> '9' ){ if (ch== '-' ) f=-1;ch= getchar ();} while (ch>= '0' &&ch<= '9' ){x=x*10+ch-48;ch= getchar ();} return x*f; } using namespace std; const int maxm=1e3+5,inf=0x3f3f3f3f; int n,m,k,t,a[maxm][maxm],cnt[maxm],ans=-1,fx[8]={-1,-1,0,1,1,1,0,-1},fy[8]={0,1,1,1,0,-1,-1,-1}; bool flag= true ; bool check( int x, int y){ return (x>=1&&x<=n&&y>=1&&y<=m); } bool calc( int x, int y){ int xx=x,yy=y,cnt=0,sum[8]={0,0,0,0,0,0,0,0}; for ( int i=0;i<8;++i){ xx=x,yy=y,cnt=0; while (a[xx][yy]==a[x][y]&&check(xx,yy)){ ++cnt; xx+=fx[i]; yy+=fy[i]; } sum[i]=cnt; } if (k<=sum[0]+sum[4]-1||k<=sum[1]+sum[5]-1||k<=sum[2]+sum[6]-1||k<=sum[3]+sum[7]-1){ flag= false ; return true ; } return false ; } void solve(){ cin>>n>>m>>k>>t; int p; flag= true ; for ( int i=1;i<=t;++i){ cin>>p; if (i%2&&flag){ //奇黑 a[n-cnt[p]][p]=1; if (calc(n-cnt[p],p)) ans=i; ++cnt[p]; } else if (flag){ //偶白 a[n-cnt[p]][p]=2; if (calc(n-cnt[p],p)) ans=i; ++cnt[p]; } } cout<<ans<<endl; return ; } signed main(){ // ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int _=1; // cin>>_; while (_--){ solve(); } return 0; } |
本文来自博客园,作者:Qiansui,转载请注明原文链接:https://www.cnblogs.com/Qiansui/p/16837714.html
分类:
oj - 牛客
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】