• NOIp2018集训test-9-2(am)


    一场讲述谁比谁更傻逼的普及组比赛,证明了

    1、老张是魔鬼(为什么有这么多套普及组题??)

    2、我最傻逼

    第 1 题 谜题

    判断1~99哪些数翻转后合法,找到最长的连续合法段的长度,为4,所以n<=4输出Yes否则输出No

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 typedef long long LL;
    16 typedef double db;
    17 using namespace std;
    18 int n;
    19 
    20 template<typename T>void read(T &x)  {
    21     char ch=getchar(); x=0; T f=1;
    22     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    23     if(ch=='-') f=-1,ch=getchar();
    24     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    25 }
    26 
    27 
    28 #define ANS
    29 int main() {
    30 #ifdef ANS
    31     freopen("puzzle.in","r",stdin);
    32     freopen("puzzle.out","w",stdout);
    33 #endif
    34     read(n);
    35     if(n<5) puts("YES");
    36     else puts("XLSB");
    37     Formylove;
    38 }
    View Code

    第 2 题 选修课

    贪心,排序后选择最大的m个,看第m大的数后面有没有和它相同的数,把这些相同的数找出来组合数算答案即可。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=100007;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int n,m,cnt[30];
    20 LL C[30][30];
    21 char s[N];
    22 
    23 template<typename T>void read(T &x)  {
    24     char ch=getchar(); x=0; T f=1;
    25     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    26     if(ch=='-') f=-1,ch=getchar();
    27     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    28 }
    29 
    30 bool cmp(const int &A,const int &B) {
    31     return A>B;
    32 }
    33 
    34 #define ANS
    35 int main() {
    36 #ifdef ANS
    37     freopen("course.in","r",stdin);
    38     freopen("course.out","w",stdout);
    39 #endif
    40     scanf("%s",s);
    41     read(m);
    42     n=strlen(s); 
    43     For(i,0,n-1) cnt[s[i]-'a'+1]++;
    44     sort(cnt+1,cnt+26+1,cmp);
    45     LL ans1=0,ans2=0;
    46     For(i,1,m) ans1+=cnt[i];
    47     if(m==26||cnt[m]==0||cnt[m+1]<cnt[m]) ans2=1;
    48     else {
    49         For(i,0,26) C[i][0]=1;
    50         For(i,1,26) For(j,1,i) C[i][j]=C[i-1][j]+C[i-1][j-1];
    51         int tpa=0,tpb=0;
    52         For(i,1,26) if(cnt[m]!=0&&cnt[i]==cnt[m]) tpa++;
    53         For(i,1,m) if(cnt[i]!=0&&cnt[i]==cnt[m]) tpb++;
    54         ans2=C[tpa][tpb];
    55     }
    56     printf("%lld %lld
    ",ans1,ans2);
    57     Formylove;
    58 }
    View Code

    第 3 题 质数

    搜根号以内的质数根号以外的贪心,不知道见过多少遍这种操作了。把数据范围看错了爆炸了。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=1007;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int T,n,m,p[N],p2[N],cnt,ans,ok[N];
    20 
    21 template<typename T>void read(T &x)  {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 #define ANS
    29 int main() {
    30 #ifdef ANS
    31     freopen("prime.in","r",stdin);
    32     freopen("prime.out","w",stdout);
    33 #endif
    34     read(T);
    35     while(T--) {
    36         read(n); read(m);
    37         cnt=0; ans=0; 
    38         int ansbs=0;
    39         For(i,1,m) { 
    40             read(p[i]); 
    41             if(p[i]<=31) p2[++cnt]=p[i]; 
    42         }
    43         int up=(1<<cnt)-1;
    44         For(i,0,up) {
    45             int tpans=0;
    46             memset(ok,0,sizeof(ok));
    47             For(j,1,cnt) if(i&(1<<j-1)) {
    48                 For(k,1,n/p2[j]) 
    49                     ok[k*p2[j]]^=1;
    50             }
    51             For(j,1,m) if(p[j]>31) {
    52                 int c1=0,c2=0;
    53                 For(k,1,n/p[j]) {
    54                     if(ok[k*p[j]]) c1++;
    55                     else c2++;
    56                 }
    57                 if(c1<c2) {
    58                     For(k,1,n/p[j]) ok[k*p[j]]^=1;
    59                 }
    60             }
    61             For(i,1,n) tpans+=ok[i];
    62             ans=max(ans,tpans);
    63         }
    64         printf("%d
    ",ans);
    65     }
    66     Formylove;
    67 }
    68 /*
    69 4
    70 10 2
    71 2 5
    72 21 4
    73 2 3 5 7
    74 100 1
    75 5
    76 100 3
    77 3 19 7
    78 */
    View Code
  • 相关阅读:
    WebApi之DOM的基本介绍
    Javascript常见数据类型API
    JavaScript作用域与对象
    Javascript数组与函数初识
    久等了,你要的 Python 书籍推荐,来了
    六种酷炫Python运行进度条
    python获取系统内存占用信息的实例方法
    在图像中隐藏数据:用 Python 来实现图像隐写术
    付费?是不可能的!20行Python代码实现一款永久免费PDF编辑工具
    Python数据分析实战:使用pyecharts进行数据可视化
  • 原文地址:https://www.cnblogs.com/Achenchen/p/9573212.html
Copyright © 2020-2023  润新知