zoukankan      html  css  js  c++  java
  • Codeforces Round #313 (Div. 2)

    比赛链接click here~~

    A 题:

    【思路】:假设输入有1就是-1,否则就是1。

    B题:给你三个矩形大小。问后两个是否能放入第一个矩形内,枚举每一种情况,存在合法的就是YES。否则就是NO。

    代码:

    // C
    #ifndef _GLIBCXX_NO_ASSERT
    #include <cassert>
    #endif
    
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    
    // C++
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    using namespace std;
    
    #define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
    #define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
    #define lowbit(a) a&-a
    #define Max(a,b) a>b?a:b
    #define Min(a,b) a>b?

    b:a #define mem(a,b) memset(a,b,sizeof(a)) typedef long long LL; typedef unsigned long long LLU; typedef double db; const int N=1e5+100; const int inf=0x3f3f3f3f; int n,m,t,ans,res,cnt,tmp; char str[N]; bool vis[N]; int mat[1005][1005];///状态之前 int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}}; int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}}; inline LL read() { int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { c=c*10+ch-'0'; ch=getchar(); } return c*f; } int a1,b1; int a2,b2; int a3,b3; bool get(int x,int y) { if(x<=a1&&y<=b1||y<=a1&&x<=b1) return 1; return 0; } int main() { while(cin>>a1>>b1) { cin>>a2>>b2; cin>>a3>>b3; bool f1=get(a2+a3,max(b2,b3)); bool f2=get(b2+b3,max(a2,a3)); bool f3=get(a2+b3,max(b2,a3)); bool f4=get(a3+b2,max(a2,b3)); if(f1||f2||f3||f4) puts("YES"); else puts("NO"); } return 0; } /* Sample test(s) input 3 2 1 3 2 1 output YES input 5 5 3 3 3 3 output NO input 4 2 2 3 1 2 output YES 100 16 41 76 24 15 NO */


    C题:

    给出一个每一个内角都是120度的六边形,问这个六边形中能够放多少 个边长为1的等边三角形

    【思路】:数学题。能够把题目中的这个六边形切割成两个等腰梯形和中间一个平行四边形。这样就能够分别算出每一个图形中所含的三角形数。最后相加即可了。

    代码:

    // C
    #ifndef _GLIBCXX_NO_ASSERT
    #include <cassert>
    #endif
    
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    
    #if __cplusplus >= 201103L
    #include <ccomplex>
    #include <cfenv>
    #include <cinttypes>
    #include <cstdalign>
    #include <cstdbool>
    #include <cstdint>
    #include <ctgmath>
    #include <cwchar>
    #include <cwctype>
    #endif
    
    // C++
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    #if __cplusplus >= 201103L
    #include <array>
    #include <atomic>
    #include <chrono>
    #include <condition_variable>
    #include <forward_list>
    #include <future>
    #include <initializer_list>
    #include <mutex>
    #include <random>
    #include <ratio>
    #include <regex>
    #include <scoped_allocator>
    #include <system_error>
    #include <thread>
    #include <tuple>
    #include <typeindex>
    #include <type_traits>
    #include <unordered_map>
    #include <unordered_set>
    #endif
    
    using namespace std;
    
    #define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
    #define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
    #define lowbit(a) a&-a
    #define Max(a,b) a>b?a:b
    #define Min(a,b) a>b?b:a
    #define mem(a,b) memset(a,b,sizeof(a))
    
    typedef long long LL;
    typedef unsigned long long LLU;
    typedef double db;
    const int N=1e5+100;
    const int inf=0x3f3f3f3f;
    int n,m,t,ans,res,cnt,tmp;
    
    char str[N];
    bool vis[N];
    
    int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
    int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
    int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};
    
    inline LL read()
    {
        int c=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9')
        {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
        {
            c=c*10+ch-'0';
            ch=getchar();
        }
        return c*f;
    }
    
    int uu[100];
    
    int calc1(int a,int h)
    {
        return (2*a*h+h*h);
    }
    int calc2(int a,int h)
    {
        return 2*a*h;
    }
    int main()
    {
        for(int i=0; i<6; ++i)
        {
            cin>>uu[i];
        }
        int h1=uu[1]+uu[2];
        int h2=min(uu[1],uu[5]);
        int h3=min(uu[2],uu[4]);
        cout<<calc1(uu[0],h2)+calc2(uu[0]+h2,h1-h2-h3)+calc1(uu[3],h3)<<endl;
        return 0;
    }

    D题:求满足条件的字符串。两个长度一样的字符串,分别切割成同样的两部分,假设两部分满足条件,则该字符串相等,推断是否相等

    【思路】假设len&1 ,则直接推断,否则。搜索两个字符串剩下的部分

    代码:

    //
    // B. Equivalent Strings
    #ifndef _GLIBCXX_NO_ASSERT
    #include <cassert>
    #endif
    
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    
    // C++
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    using namespace std;
    
    #define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
    #define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
    #define lowbit(a) a&-a
    #define Max(a,b) a>b?a:b
    #define Min(a,b) a>b?b:a
    #define mem(a,b) memset(a,b,sizeof(a))
    
    typedef long long LL;
    typedef unsigned long long LLU;
    typedef double db;
    const int N=2*1e5+100;
    const int inf=0x3f3f3f3f;
    int n,m,t,ans,res,cnt,tmp;
    
    int hh[28];
    char str1[N],str2[N];
    bool vis[N];
    int mat[1005][1005];
    
    int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
    int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
    int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};
    
    inline LL read()
    {
        int c=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9')
        {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
        {
            c=c*10+ch-'0';
            ch=getchar();
        }
        return c*f;
    }
    
    int a1,b1;
    int a2,b2;
    int a3,b3;
    
    bool dfs(char *s,char *t,int len)
    {
        if(len&1) return strncmp(s,t,len)==0;
        mem(hh,0);
        for(int i=0; i<len; ++i)
        {
            hh[s[i]-'a']++;
            hh[t[i]-'a']--;
        }
        for(int i=0; i<26; ++i)
        {
            if(hh[i]!=0) return false;
        }
        len/=2;
        if(dfs(s,t,len)&&dfs(s+len,t+len,len)) return true;
        if(dfs(s+len,t,len)&&dfs(s,t+len,len)) return true;
        return false;
    }
    int main()
    {
        scanf("%s%s",str1,str2);
        int len=strlen(str1);
        printf("%s
    ",dfs(str1,str2,len)?"YES":"NO");
        return 0;
    }
    


  • 相关阅读:
    Rust 1.40.0 发布
    Rust程序交叉编译到aarch64(armv8)目标
    中西的根本区别:理性和感性 贺刚
    使用Rust加速Python
    让你的Python代码更快运行的 5 种方法
    Python基于pyCUDA实现GPU加速并行计算功能入门教程
    用 Psyco 让 Python 运行得像 C 一样快
    illuminate/routing 源码分析之注册路由
    php利用32进制实现对id加密解密
    微信小程序支付全问题解决
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/6767093.html
Copyright © 2011-2022 走看看