Codeforces Round #288 (Div. 2) 合集

本文解析了Codeforces竞赛中的三道题:Pasha and Pixels要求找出最小步数绘制2x2方块;Anton and currency you all know寻找数字中可替换的最大偶数值;Anya and Ghosts则挑战如何用最少的蜡烛照亮整个夜晚。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Codeforces Round #288 (Div. 2) A. Pasha and Pixels

有N*M个空白格 , 操作K次、每次把(x,y)所代表的格子涂黑 , 问你最少通过几次操作能画出一个2*2的方框

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int Map[1005][1005] ;
int n , m , k ;

bool check(int x , int y)
{
     if(Map[x+1][y] && Map[x][y+1] && Map[x+1][y+1])
          return true;
     if(Map[x-1][y] && Map[x][y+1] && Map[x-1][y+1])
          return true;
     if(Map[x-1][y] && Map[x][y-1] && Map[x-1][y-1])
          return true;
     if(Map[x+1][y] && Map[x][y-1] && Map[x+1][y-1])
          return true;
     return false;
}
int main()
{
     int x , y;
     while(cin >> n >> m >> k)
     {
          int ans = 0;
          memset(Map, 0 ,sizeof(Map));
          for(int i = 1 ; i <= k ; i++)
          {
               cin >> x >> y;
               Map[x][y] = 1;
               if(check(x,y) && ans == 0)
               {
                    ans = i ;
               }
          }
          cout << ans << endl;
     }
     return 0;
}



Codeforces Round #288 (Div. 2)  B. Anton and currency you all know

题目给出一个数字、让你在这个数字中找到一个偶数和最后一个数交换形成新的数、问你这个数最大值是多少

前后FOR一遍就OK 

比赛的时候太贪心了直接枚举结果在重判时TLE了。。

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
     string str;
     cin >> str;
     int len = str.length();
     for(int i = 0 ; i < len ; i++)
     {
          if(str[i] % 2 == 0 && str[len - 1] > str[i])
          {
               swap(str[i],str[len-1]);
               cout << str << endl;
               return 0;
          }
     }
     for(int i = len - 2 ; i >= 0 ; i--)
     {
          if(str[i] % 2 == 0)
          {
               swap(str[i],str[len-1]);
               cout << str << endl;
               return 0;
          }
     }
     cout << "-1" << endl;
     return 0;
}


C. Anya and Ghosts

第一行输入  鬼的总数 蜡烛燃烧持续时间 每个鬼来访时所需要点亮的蜡烛数目

问你最少需要多少蜡烛能让Anya度过这个夜晚

郁闷了比赛的时候写个点蜡烛函数然后在27组WA了 后来写到main里面AC不知道问题出在哪里

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
     int m , t , r , ghost[305] , light[700] , vis[700];
     while(cin >> m >> t >> r)
     {
          for(int i = 0 ; i < m ; i++)
          {
               cin >> ghost[i];
               ghost[i] += 320;
          }

          if(r > t)
               cout << "-1" << endl;
          else
          {
               sort(ghost , ghost + m);
               memset(light,0,sizeof(light));
               memset(vis,0,sizeof(vis));
               int cnt = 0;
               for(int i = 0 ; i < m ; i++)
               {
                    while( light[ ghost[i] ] < r)
                    {
                         cnt++;
                         int pos = ghost[i];
                         while(vis[--pos] !=0);
                         vis[pos] = 1;
                         for(int i = 1 ; i <= t ;i++)
                              light[pos + i]++;
                    }
               }
               cout << cnt << endl;
          }
     }
     return 0;
}

以下是WA的代码谁能帮帮我解决这为什么WA

</pre><pre name="code" class="cpp">#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int m , t , r , ghost[305] , light[700] , vis[700];
void SetR(int pos)
{
     while(vis[--pos] !=0);
     vis[pos] = 1;
     for(int i = 1 ; i <= t ;i++)
          light[pos + i]++;
}

int main()
{
     while(cin >> m >> t >> r)
     {
          for(int i = 0 ; i < m ; i++)
          {
               cin >> ghost[i];
               ghost[i] += 320;
          }

          if(r > t)
               cout << "-1" << endl;
          else
          {
               memset(light,0,sizeof(light));
               memset(vis,0,sizeof(vis));
               int cnt = 0;
               for(int i = 0 ; i < m ; i++)
               {
                    while( light[ ghost[i] ] < r)
                    {
                         cnt++;
                         SetR(ghost[i]);
                    }
               }
               cout << cnt << endl;
          }
     }
     return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值