Codeforces Round #288 (Div. 2) ABC

来源:互联网 发布:网络拓扑图怎么简单画 编辑:程序博客网 时间:2024/05/16 16:06

A - Pasha and Pixels :在一个棋盘上不断的放棋子,当有放满2 * 2的操作出现的时候输出那个操作的序号.按题意判断就行了

#include <iostream>#include <cstring>#include <set>using namespace std;bool mp[1010][1010];bool judge( int x , int y ){mp[x][y] = true;if( mp[x][y] && mp[x+1][y] && mp[x][y+1] && mp[x+1][y+1] ){return true;}else if( mp[x-1][y-1] && mp[x-1][y] && mp[x][y-1] && mp[x][y] ){return true;}else if( mp[x][y-1] && mp[x][y] && mp[x+1][y] && mp[x+1][y-1] ){return true;}else if( mp[x-1][y] && mp[x][y] && mp[x][y+1] && mp[x-1][y+1] ){return true;}return false;}int main(){int n , m , k , x , y;memset( mp , false , sizeof(mp) );cin >> n >> m >> k;for( int i = 1 ; i<=k ; i++ ){cin >> x >> y;if( judge(x,y) ){cout << i << endl;return 0;}}cout << 0 << endl;return 0;}

B - Anton and currency you all know交换一串数字中的两个,使剩下的是偶数且尽量大.for一遍就好

#include <iostream>#include <string>#include <algorithm>#include <set>using namespace std;string str;int main(){    cin >> str;    int len = str.length();    char ans = '*';    int res = -1;    for( int i = 0 ; i<len ; i++ )    {        if( (int)(str[i]-'0')%2==0 )        {            res = i;            ans = str[i];            if( ans<str[len-1] )            {                swap( str[i] , str[len-1] );                cout << str << endl;                return 0;            }        }    }    if( ans!='*' )    {        swap( str[res] , str[len-1] );        cout << str << endl;        return 0;    }    cout << -1 << endl;    return 0;}

C - Anya and Ghostsm 只幽灵,每只出现在时间点w[i]且持续一秒,你手上有无数只蜡烛,每只蜡烛能燃烧t时间,而每只幽灵出现的时候需要同时点r只蜡烛.你每次每秒只能点一只蜡烛问抗的住m只幽灵最少需要多少只蜡烛.

记录下幽灵出现的点,然后先确保每只幽灵都能点够r只蜡烛,即比如在w[i]时刻出现蜡烛,就在w[i]-1-r ~ w[i] -1的时候先点上蜡烛.然后枚举所有时间点(因为才300),对于每只幽灵,如果有多点的蜡烛,那么就把多出的蜡烛去掉,最后剩下的蜡烛数目就是最少需要点的数目.

#include <map>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;queue <int> qu;int w[400];int main (){int m, t, r;while (~scanf("%d%d%d", &m, &t, &r)){int cnt = 0, ans = 0;for (int i = 1; i <= m; ++i){scanf("%d", &w[i]);}while (!qu.empty()){qu.pop();}if (r > t){printf("-1\n");continue;}bool flag = true;for (int i = w[1] - r; i <= w[1] - 1; ++i){qu.push (i + 1);++cnt;++ans;}for (int i = 2; i <= m; ++i){while (!qu.empty ()){int u = qu.front();if (u + t - 1 < w[i]){qu.pop();--cnt;}else{break;}if (cnt == 0){break;}}if (cnt >= r){continue;}int cur = r - cnt;if (cur > t || w[i] - cur < w[i - 1]){flag = false;break;}for (int j = w[i] - cur; j <= w[i] - 1; ++j){qu.push (j + 1); //开始亮的时间++cnt;++ans;}}if (!flag){printf ("-1\n");}else{printf("%d\n", ans);}}return 0;}


0 0
原创粉丝点击