0

0

Codeforces #246(div2)_html/css_WEB-ITnose

php中文网

php中文网

发布时间:2016-06-24 12:04:31

|

999人浏览过

|

来源于php中文网

原创

a:a. choosing teams

.题目就不介绍了,直接统计即可。

AC代码:

Kive
Kive

一站式AI图像生成和管理平台

下载

立即学习前端免费学习笔记(深入)”;

#include#include#includeusing namespace std;int cnt[6];int main(){    int n,k,i,x;    while(cin>>n>>k)    {        memset(cnt,0,sizeof(cnt));        for(i=0;i>x;            cnt[5-x]++;        }        int ans=0;        for(i=k;i<=5;i++)        {            ans+=cnt[i];        }        ans/=3;        cout<  

立即学习前端免费学习笔记(深入)”;

B:B. Football Kit

题目真的好难懂。。反正我读了很久很久,题目意思是说有n支队伍打锦标赛,分主场客场,每支队伍打主场穿颜色A,打客场穿颜色B的衣服,如果两支队伍颜色衣服一样,那么打客场的还是穿原本自己主场的衣服,就是A衣服,哎。。就这个地方理解坑了许久,,只需要统计一下即可。


AC代码:

立即学习前端免费学习笔记(深入)”;

#include#include#includeusing namespace std;const int maxn=100005;int x[maxn],y[maxn];int p[maxn];int main(){    int n;    while(cin>>n)    {        memset(p,0,sizeof(p));        for(int i=0;i>x[i]>>y[i];            p[x[i]]++;        }        for(int i=0;i  

立即学习前端免费学习笔记(深入)”;

C:C. Prime Swaps

题目意思是给你n个无序的数字,让你排序。不过有一点如果i和j这个位置,交换,(如果j>i)需要j-i+1为素数。其实可以用冒泡yy一下,不过很快就证明不行,题目上面说了,最大是五倍的n。然后就开始网上找怎么分成素数。

哥德巴赫猜想有两个内容:

第一部分叫做奇数的猜想,
第二部分叫做偶数的猜想。奇数的猜想指出,任何一个大于等于7的奇数都是三个素数的和。
偶数的猜想是说,大于等于4的偶数一定是两个素数的和。

不过需要打表。

我的做法没有用到这个猜想。其实可以利用题目的条件,有n个数,这n个数字刚好是1~n,所以可以直接定位,然后我们可以每次交换最远的,利用的贪心的算法。一般只需要最多三四次就可以把这个数字换到原位,实际上也利用到了上面的猜想。。


AC代码:

立即学习前端免费学习笔记(深入)”;

#include#include#include#includeusing namespace std;const int maxn=100005;int a[maxn],pos[maxn],mark[maxn];int res[5*maxn][2];void sxprime(){    memset(mark, true, sizeof(mark));    mark[0] = mark[1] = false;    for(int i=2; i <= sqrt(maxn-1) ; i++)    {        if(mark[i])        {            for(int j=i*i; j < maxn-1 ; j+=i)                mark[j] = false;        }    }}int main(){    sxprime();    int i,j,n;    while (cin>>n)    {        for (int i=1; i<=n; i++)        {            scanf("%d",&a[i]);            pos[a[i]]=i;        }        int tt=0,p=1;        for (int i=1; i<=n; i++)        {            while (pos[i]!=p)            {                for (j=pos[i]-p+1; j>=2; j--)                    if (mark[j])                    {                        int x=pos[i]+1-j;                        res[tt][0]=x;                        res[tt++][1]=pos[i];                        int l,r,tmp;                        l=x,r=pos[i];                        tmp=a[l];                        a[l]=a[r];                        a[r]=tmp;                        tmp=pos[a[l]];                        pos[a[l]]=pos[a[r]];                        pos[a[r]]=tmp;                        break;                    }            }            p++;        }        printf("%d\n",tt);        for (int i=0; i  

立即学习前端免费学习笔记(深入)”;

D:D. Prefixes and Suffixes

立即学习前端免费学习笔记(深入)”;

D. Prefixes and Suffixes

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have a string s?=?s1s2...s|s|, where |s| is the length of string s, and si its i-th character.

Let's introduce several definitions:

  • A substring s[i..j] (1?≤?i?≤?j?≤?|s|) of string s is string sisi?+?1...sj.
  • The prefix of string s of length l (1?≤?l?≤?|s|) is string s[1..l].
  • The suffix of string s of length l (1?≤?l?≤?|s|) is string s[|s|?-?l?+?1..|s|].
  • Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.

    Input

    The single line contains a sequence of characters s1s2...s|s| (1?≤?|s|?≤?105) ? string s. The string only consists of uppercase English letters.

    Output

    In the first line, print integer k (0?≤?k?≤?|s|) ? the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring citimes. Print pairs li ci in the order of increasing li.

    Sample test(s)

    input

    ABACABA

    output

    31 43 27 1

    input

    AAA

    output

    31 32 23 1



    立即学习前端免费学习笔记(深入)”;

    意思就是让你求首先前缀等于后缀,然后求原串中有多少个这样的串的个数。

    立即学习前端免费学习笔记(深入)”;

    开始在用manacher想,但是无果,于是想kmp,然后就开始写了,getnext,然后统计个数,但是当时脑筋犯迷糊,不知道怎么统计前缀等于后缀,实际上自己和自己匹配就可以了。。YY的能力越来越差了。

    然后在KMP中统计前缀出现的个数,然后再往前递推,因为如果next[k]!=0,那么说明k这一点记录的cnt会包含cnt[next[k]]的,然后就可以递推了。详见代码。


    AC代码:

    立即学习前端免费学习笔记(深入)”;

    #include#include#include#includeusing namespace std;const int maxn=100005;char p[maxn];int cnt[maxn],len,t;int next[maxn],ans[maxn][2];void getnext(){     int i,j;     next[0]=0,next[1]=0;     for(i=1;i=1;k--)  //往前递推,长度长的可能会包含长度短的.        if(next[k])            cnt[next[k]]+=cnt[k];    j=next[j];    t=0;    ans[t][0]=len;    ans[t++][1]=1;    while(j)    {        ans[t][0]=j;        ans[t++][1]=cnt[j];        j=next[j];    }}int main(){    int i;    while(cin>>p)    {        len=strlen(p);        getnext();        KMP();        printf("%d\n",t);        for(i=t-1;i>=0;i--)            printf("%d %d\n",ans[i][0],ans[i][1]);    }    return 0;}/*ABACABAAAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA*/


    立即学习前端免费学习笔记(深入)”;


    HTML速学教程(入门课程)
    HTML速学教程(入门课程)

    HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

    下载

    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

    相关专题

    更多
    html编辑相关教程合集
    html编辑相关教程合集

    本专题整合了html编辑相关教程合集,阅读专题下面的文章了解更多详细内容。

    38

    2026.01.21

    三角洲入口地址合集
    三角洲入口地址合集

    本专题整合了三角洲入口地址合集,阅读专题下面的文章了解更多详细内容。

    18

    2026.01.21

    AO3中文版入口地址大全
    AO3中文版入口地址大全

    本专题整合了AO3中文版入口地址大全,阅读专题下面的的文章了解更多详细内容。

    234

    2026.01.21

    妖精漫画入口地址合集
    妖精漫画入口地址合集

    本专题整合了妖精漫画入口地址合集,阅读专题下面的文章了解更多详细内容。

    61

    2026.01.21

    java版本选择建议
    java版本选择建议

    本专题整合了java版本相关合集,阅读专题下面的文章了解更多详细内容。

    3

    2026.01.21

    Java编译相关教程合集
    Java编译相关教程合集

    本专题整合了Java编译相关教程,阅读专题下面的文章了解更多详细内容。

    14

    2026.01.21

    C++多线程相关合集
    C++多线程相关合集

    本专题整合了C++多线程相关教程,阅读专题下面的的文章了解更多详细内容。

    6

    2026.01.21

    无人机驾驶证报考 uom民用无人机综合管理平台官网
    无人机驾驶证报考 uom民用无人机综合管理平台官网

    无人机驾驶证(CAAC执照)报考需年满16周岁,初中以上学历,身体健康(矫正视力1.0以上,无严重疾病),且无犯罪记录。个人需通过民航局授权的训练机构报名,经理论(法规、原理)、模拟飞行、实操(GPS/姿态模式)及地面站训练后考试合格,通常15-25天拿证。

    27

    2026.01.21

    Python多线程合集
    Python多线程合集

    本专题整合了Python多线程相关教程,阅读专题下面的文章了解更多详细内容。

    1

    2026.01.21

    热门下载

    更多
    网站特效
    /
    网站源码
    /
    网站素材
    /
    前端模板

    精品课程

    更多
    相关推荐
    /
    热门推荐
    /
    最新课程
    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号