zoukankan      html  css  js  c++  java
  • Codeforces #426(div2)

    Codeforces #426(div2)


    A.The Useless Toy
    题意:
    字符>、<、^、v都可以看成一个旋转对应另一个。现在给你一个其中的两个字符,和旋转的次数,如果从字符A到B是顺时针形成的,输出cw,逆时针输出ccw,无法确定的时候输出undefined。
    思路:
    偶数的时候逆时针成立的话顺时针必定成立,必定输出undefined 。然后分别对1次和3次进行讨论。

    #include "bits/stdc++.h"
    using namespace std;
    int main(int argc, char const *argv[])
    {
        char ch1, ch2;
        int n;
        scanf("%c%*c%c", &ch1, &ch2);
        scanf("%d", &n);
        if (n%2 == 0) printf("undefined
    ");
        else {
            n %= 4;
            if (n == 1) {
                if ((ch1=='^'&&ch2=='>')||(ch1 == '>'&&ch2=='v')||(ch1=='v'&&ch2=='<')||(ch1=='<'&&ch2=='^')) printf("cw
    ");
                else printf("ccw
    ");
            }
            else {
                if ((ch1=='^'&&ch2=='>')||(ch1 == '>'&&ch2=='v')||(ch1=='v'&&ch2=='<')||(ch1=='<'&&ch2=='^')) printf("ccw
    ");
                else printf("cw
    ");
            }
        }
        return 0;
    }
    

    B.The Festive Evening
    题意:
    果冻城堡开会,会有一些没有邀请的人混进去。城堡有26个门口A-Z代表每个城堡门。客人只能一个一个的进入。城堡每个门从第一个人到达开始打开直到最后一个人关闭。这段时间应该有守卫在值班,否则会有没收到邀请的人混进去。现在有n个客人到访的顺序和k个守卫,检测是否会有不请自来的人进去。
    思路:
    找的每个门口开门和关门的时间,枚举每个时间点,检测最大的开门数目是否大于守卫的数目。

    #include "bits/stdc++.h"
    using namespace std;
    const int maxn = 1e6 + 10;
    char s[maxn];
    int open[30], close[30];
    int main(int argc, char const *argv[])
    {
    	int n, k;
    	scanf("%d%d", &n, &k);
    	scanf("%s", s);
    	memset(open, -1, sizeof(open));
    	for (int i = 0; i < n; i++) {
    		int idx = s[i] - 'A';
    		if (open[idx] == -1) open[idx] = i;
    		close[idx] =  i;
    	}
    	int maxx = 0;
    	for (int i = 0; i < n; i++) {
    		int t = 0;
    		for (int j = 0; j < 26; j++) {
    			if (open[j] != -1 &&i >= open[j] && i <= close[j]) t++;
    		}
    		maxx = max(t, maxx);
    	}
    	if (maxx>k) printf("YES
    ");
    	else printf("NO
    "); 
    	return 0;
    }
    

    C. The Meaningless Game
    题意:
    Slastyona和她的狗在做游戏,每轮选择一个数k,然后谁先发出声音,谁获胜,获胜的人的分数乘上(k^2),输的人乘上(k)。现在她的数据丢了,只剩下分数,让你判断分数对不对。
    思路:
    我的思路复杂了,结果各种优化也是TLE,其实对于这两个分数,他们的乘积应该是某个正整数的三次方,直接二分。

    #include "bits/stdc++.h"
    using namespace std;  
    typedef long long LL;  
    bool find(LL x) {
        int lb = 1,ub = 1e6;
        LL mid;  
        while(lb <= ub) {
            mid = (lb+ub)/2;  
            if(mid*mid*mid == x) return true;  
            if(mid*mid*mid < x) lb = mid + 1;  
            else ub = mid-1;  
        }  
        return false;  
    }  
    int main(int argc, char const *argv[]) {
        int T;  
        scanf("%d", &T);
        while(T--) {
            LL a, b;  
            scanf("%lld%lld",&a, &b);  
            if(a*a%b == 0 && b*b%a == 0 && find(a*b)) printf("Yes
    ");             
            else printf("No
    ");  
        }  
        return 0;  
    }  
    
    

  • 相关阅读:
    开发者说:愿为你点亮“懂环境知冷暖”智能的灯
    云图说 | 通过Helm模板快速部署中间件应用
    int指令03 零基础入门学习汇编语言66
    C++语言与OO思想介绍 C++快速入门01
    C++语言与OO思想介绍 C++快速入门01
    端口01 零基础入门学习汇编语言67
    端口02 零基础入门学习汇编语言68
    int指令03 零基础入门学习汇编语言66
    端口02 零基础入门学习汇编语言68
    PE格式详细讲解5 系统篇05|解密系列
  • 原文地址:https://www.cnblogs.com/cniwoq/p/7262502.html
Copyright © 2011-2022 走看看