华东交通大学2016年ACM“双基”程序设计竞赛

来源:互联网 发布:t315hw04 vb 编辑:程序博客网 时间:2024/04/30 15:19

1001简单题

Problem Description
输入一个非负的int型整数,是奇数的话输出"ECJTU",是偶数则输出"ACM"。

Input

多组数据,每组数据输入一个x。
输入到文件结尾结束(scanf函数返回值不为EOF时),例如:
#include<cstdio>
using namespace std;
int main()
{
int x;
while (scanf("%d", &x)!=EOF) {
if (x%2==1) printf("...\n");
else printf("...\n");
}
  return 0;
}

Output

每组输出数据占一行。

Sample Input

12

Sample Output

ECJTUACM

Author

zhengjinke2123 

分析:奇数的话输出"ECJTU",偶数则输出"ACM"即可。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;int main(void){    int n;    while(cin>>n)    {        if(n%2==0) puts("ACM");        else puts("ECJTU");    }     return 0;}

1002acm小学弟

Problem Description

今天小学弟又训练完了,但是小学弟又不想看球赛,于是小学弟看马赛了。他发现马鞍是一个奇怪的东西。于是小学弟根据马鞍定义了一种马鞍数:在一个二位矩阵中,马鞍数在当前行是最小的,在当前列是最大的,并且这个数在当前行和列都是独一无二的。小学弟现在马上打开电脑写出了一个程序求出了矩阵里面马鞍数的数量。那么,你能求出来吗?这是一道非常简单的题目。

Input

输入包含多组,每一组输入一个n(1<=n<=1000),接下来n行,每一行有n个数a1,a2,a3……,an(0<=ai<=10000000000)。

Output

输出马鞍数的数量。

Sample Input

51 2 3 4 50 0 0 0 40 0 0 0 30 0 0 0 20 0 0 0 1

Sample Output

1

Author

zhengjinke2123 

分析:在二位矩阵中,该数在当前行是最小的,在当前列是最大的,并且这个数在当前行和列都是独一无二的,求这样的数有即可。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;long long int a[1010][1010]; //二维数组。 long long int mi[1010];      //记录每行的最小值 long long int mark[1010];    //记录每行的最小值在第几列 void init()                  //初始化 {    memset(a,0,sizeof(a));    memset(mark,0,sizeof(mark));}int main(void){int n;while(scanf("%d",&n)!=EOF){    init();    for(int i=0;i<n;i++)        mi[i]=100000*100000+10;        int cnt=0;for(int i=0;i<n;i++){for(int j=0;j<n;j++){scanf("%lld",&a[i][j]);if(a[i][j]<mi[i]){mi[i]=a[i][j];       //更新数组mi mark[i]=j;           //更新数组mark }}}for(int i=0;i<n;i++){int flag=0;for(int j=0;j<n;j++){if(a[i][mark[i]]<a[j][mark[i]]){flag=1;break;}}if(flag==0) cnt++;}printf("%d\n",cnt);} return 0;}

1003寻根

Problem Description

风雨漂泊异乡路,
浮萍凄清落叶飞。
游子寻根满愁绪,
一朝故土热泪归。
Hey ecjtuer! 刚刚学习了二叉树的知识,现在来考察一下..
给你一个深度为h的满二叉树,根节点为1(根的深度为0),根据先序遍历对节点进行编号,如下图是对一个深度为2的满二叉树的节点进行编号。
现在希望你告诉我以第n个叶子节点(从左往右数)为起点,终点为根节点,形成的一条链经过的节点的序号之和。


        1
     /      \
    2       5 
  /   \     /  \
 3   4   6   7

Input

输入两个数 h 代表二叉树的深度 n代表查询的叶子节点
1<=h<=50
1<=n<=2^h
注意多组数据

Output

输出所求链的序号之和模1e9+7的余数

Sample Input

2 3

Sample Output

12

Author

zhengjinke2123 

分析:发现其中的规律即可。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;const int mod = 1e9+7;long long a[70],b[70];void init(){b[0]=1;    for(int i=1;i<=50;i++) b[i]=(b[i-1]*2)%mod; } int main(){    init();long long h,n;while(scanf("%lld%lld",&h,&n)!=EOF)    {       memset(a,0,sizeof(a));       n--;        long long len=0,sum=1,temp=1;         while(n>0)        {     a[len++]=n%2;            n/=2;        }        for(int i=h-1;i>=0;i--)        {            if(a[i]==1) temp+=b[i+1];            else temp++;            sum=(sum%mod+temp%mod)%mod;        }        printf("%lld\n",sum%mod);     }    return 0;}

1004LB的公式

Problem Description

LB是个十分喜欢钻研的人,对什么事都要搞明白。
有一天他看到一个公式,((a-b)*c+d*e)/f=k。他想如果给定K的值,
一共有多少种不同整数的组合(a,b,c,d,e,f)使公式成立,(-50≤a,b,c,d,e,f≤50)LB算了很久都没有算出来,
所以他向你求助,由于答案很大,所以对1e9+7取模

Input

第一行只包含一个整数T(T≤100),表示测试用例的个数。
对于每个测试用例,第一行只包含一个整数K(-500≤K≤500)

Output

对于每个测试用例,输出最后对1e9+7取模的答案。

Sample Input

1500

Sample Output

27194104

Author

zhengjinke2123 

分析:暴力打表
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;const int mod = 1e9+7;long long int ans[]={166016493, 363555504, 451321856, 432361944, 483089496, 403838348, 522892816, 379753020, 479758456, 422358824, 476068076, 342985428, 531363336, 327104400, 433444172, 430990768, 441750248, 303669448, 469537320, 296707704, 456858172, 383109056, 372544828, 282949584, 473789384, 320002640, 342259472, 332137384, 391450988, 252214716, 441983912, 245579524, 357121208, 307103796, 301656864, 302842644, 402084816, 226543708, 286787464, 277098284, 363262652, 214571900, 358732952, 208765964, 301165260, 300782388, 258824248, 197564524, 347268336, 217151608, 285972688, 223173040, 255962736, 171974960, 281545656, 212493648, 273157924, 206053048, 207452852, 157746312, 317029656, 153357824, 196685596, 220511836, 225933996, 180831800, 242193292, 141185576, 202804104, 177146256, 233608052, 133824520, 254979228, 130354808, 169017460, 193354516, 184633216, 152525304, 202518324, 120707048, 216576496, 154908208, 153836684, 114856192, 224095800, 137746984, 147040852, 136802040, 175718620, 106863400, 210648568, 125891976, 155481984, 128016728, 134822276, 123835904, 190112136, 97481256, 146237064, 134645080, 168159704, 93267632, 150235992, 91323064, 140874852, 150767256, 113509264, 87637440, 162400880, 85887184, 140972480, 106941648, 144983168, 82571280, 134790616, 102689992, 115857120, 110916488, 101142720, 92697640, 171242628, 83239992, 97548736, 96259776, 108087576, 93599160, 140339740, 72585384, 112630268, 91636672, 114167504, 70124304, 134105624, 82815824, 88044248, 108925368, 104641132, 66707080, 111698808, 65635392, 126101808, 83541096, 82605336, 72838712, 129570472, 76748496, 80112640, 91353528, 89838672, 60723536, 120985800, 59825528, 93622948, 79620760, 93676832, 71502264, 107911368, 57261296, 73399488, 69667856, 105626748, 68267544, 94381036, 54889784, 80679648, 86493512, 69459808, 53405344, 113530548, 55758792, 84369288, 70970120, 76724992, 51310096, 82753960, 73835808, 86115136, 61789768, 64209184, 49354704, 111589600, 48739104, 75205888, 59512176, 77293124, 59225872, 77018568, 52823344, 69795912, 70995888, 75289984, 45831248, 90429736, 45288232, 58215304, 70870000, 75532232, 44230416, 81312820, 43720536, 83962708,53519216, 55574464, 50517840, 78343912, 53078968, 54342536, 58222640, 68071808, 46989496, 91031896, 40857648, 58365152, 50083944, 52031544, 50421616, 80915388, 46943896, 50939120, 48508392, 73550816, 42402656, 63608400, 38307592, 68539356, 64000440, 48874600, 37527096, 69815040, 37141232, 61906912, 57091832, 56637296, 36390528, 65745196, 45796064, 51654944, 44271232, 54982680, 35327312, 83467608, 34979232, 49533584, 46446896, 49716784, 50007528, 56907488, 37629040, 52628560, 41783032, 56195908, 33351008, 72678872, 38424056, 42698176, 50337608, 52099368, 32416424, 54021032, 38625080, 58098208, 43038840, 41172368, 31542664, 66066656, 37714528, 48904928, 38481488, 44603296, 30698240, 64665108, 30430928, 49708456, 46380840, 39063120, 41050704, 57193576, 29649936, 38410672, 39897464, 61563864, 29138480, 48964048, 28882504, 41686840, 44557088, 42777072, 34456056, 60776824, 29190920, 45098264, 34698008, 40349688, 27702160, 53739628, 33214528, 43249216, 39788616, 35385840, 30600512, 61973480, 32679024, 34831472, 33042480, 44174616, 31908480, 46987608, 26177640, 47637216, 32270392, 41830072, 25764368, 52517392, 25558808, 33253696, 47500440, 36761664, 25166496, 40835712, 27870776, 48487944, 30814456, 39958040, 26680928, 48176504, 32839472, 31800120, 30133536, 38559008, 29543160, 51230176, 23858440, 34658072, 32587592, 30883672, 28474872, 54166504, 23342656, 32076216, 28826888, 42217536, 25768896, 41649792, 28025376, 36535696, 36067856, 29601920, 22509856, 41753600, 22345936, 43279980, 32096040, 39494756, 22043968, 35965744, 26515800, 31858248, 32333976, 28397488, 21578512, 54401788, 22478912, 28018416, 28989184, 37078056, 25618976, 34549920, 20993464, 35969048, 28963048, 34176160, 24020736, 38657144, 20566832, 30736320, 32683064, 32998680, 22010752, 41239336, 20157112, 37325488, 24964744, 26235776, 19894536, 41069100, 29623416, 25893384, 27396272, 28660016, 19506880, 41092680, 21519520, 35581504, 24012176, 25248960, 23206648, 41310616, 19002368, 24935568, 28452344, 39022192, 18769824, 30852576, 20308208, 27259072, 30925816, 28604608, 20902904, 37313728, 18293784, 30357272, 22699416, 26598784, 20999280, 33770648, 21792840, 30537816, 22284528, 27147224, 17738232, 45568272, 17624352, 23174640, 24669912, 27217712, 23151800, 28732848, 20132912, 25377536, 25182248, 28704680, 17092224, 37797664, 16989408, 26412968, 26243384, 24785136, 18899360, 27756656, 16692320, 34631752, 26950208, 24002720, 16505264, 31435328, 19939224, 21629312, 20399280, 30353816, 16213936, 37136520, 18488936, 23701688, 20062280, 21142800, 23478344, 32924936, 15856576, 20907008, 21965992, 30132376, 15666544, 32826248, 15576960, 25691792, 24190800, 20457000, 15411360, 32409856, 17833688, 25843232, 19071968, 23819728, 17441008, 25150936, 20298424, 26446808, 20101392, 19803808, 14904432, 37814288, 16352328, 19585824, 22785328, 24201384, 17802848, 26260484, 14576368, 22833664, 18171336, 28103780, 14416888, 27835344, 15223680, 21107048, 25481344, 23701192, 16522256, 23626352, 14106600, 27194104};int main(){    int T,n;    scanf("%d",&T);    {        while(T--)        {            scanf("%d",&n);            if(n<0) n=-n;            printf("%lld\n",ans[n]%mod);        }    }    return 0;}

1005upupup

Problem Description

最近侯ry感觉自己在数学方面的造诣不忍直视;他发现他的学习速率呈一个指数函数递增,疯狂的陷入学习的泥潭,无法自拔;他的队友发现了他的学习速率y=e^(b*lna+lnc);
e是科学界非常重要而常见的常数,e=2.718281828……。
侯ry由于数学很差不会算学习数率y,现求助于学弟,感激不尽;

Input

多组数据,每组数据输入三个整数a,b,c(a,c<=10^12,b<=10^100000)

Output

一个整数y,对10^9+7取模

Sample Input

2 3 10

Sample Output

80

Author

zhengjinke2123

分析:简单化简下可以得学习效率y=a^b*c%mod;给了三个整数a,b,c(a,c<=10^12,b<=10^100000) 求y的值。
/*当你要计算 A^B%C的时候因为此题中的B很大,达到10^100000,所以我们应该联想到降幂公式。 降幂公式:A^B%C = A^(B%phi(C) + phi(C))%C分两种情况: 当B<=phi(C)时,直接用快速幂计算A^B mod C当B>phi(C)时,用快速幂计算A^(B mod phi(C)+phi(C)) mod C */#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;const int mod = 1e9+7;typedef long long ll;ll phi(ll n)   //求欧拉函数值 {int ans=n,temp=n;for(int i=2;i*i<=temp;i++) {if(temp%i==0) {ans-=ans/i;while(temp%i== 0) temp/=i;}}if(temp>1) ans-=ans/temp;return ans;}ll mod_pow(ll x,ll n,ll mod)  //快速幂 {   ll ans=1;while(n) {if(n%2==1) ans=ans*x%mod;x=x*x%mod;n/=2;}return ans;}ll a,c;char b[1000010];int main() {while(scanf("%lld%s%lld",&a,b,&c)!=EOF) {c%=mod;a%=mod;ll phic=phi(mod);int i,len=strlen(b);ll res=0,ans; for(i=0;i<len;i++) {res=res*10+b[i]-'0';if(res>phic) break;   }if(i==len)  ans=((mod_pow(a,res,mod)%mod)*c)%mod;else {res=0;for(i=0;i<len;i++) {res=res*10+b[i]-'0';res%=phic;}ans=(mod_pow(a,res+phic,mod)%mod)*c%mod;}printf("%lld\n",ans);}return 0;}

1007acm小学妹

Problem Description

ACM小学妹在今天的暑假训练结束后,想看球赛放松一下。当他打开电脑时查询到联盟今天直播N场球赛,每场球赛的起止时间(S1,E1),(S2,E2),...,(SN,EN)。现在小学妹想今天看完所有的球赛直播,不至于留到明天看重播了,毕竟明天依旧是要训练的。当小学妹看完这场球赛要切换到其他球赛时是不需要时间的。现在小学妹用自己训练用的电脑来看球赛,但是可能不够。毕竟小学妹自己的电脑最多只能同时播放1场直播,现在小学妹需要借一些电脑来同时播放球赛。本来小学妹自己是可以求出最少需要借多少台电脑来同时观看的,但是今天训练太累了,你可以帮助他吗?

Input

包含多组输入,第一行输入一个整数N(1≤N≤100000),表示任务的数目。以下N行每行两个整数Si,Ei,(0≤Si<Ei≤1000000000),表示任务的起至时间。

Output

输出小学妹最少需要借的电脑数目。

Sample Input

51 102 76 93 47 10

Sample Output

2

Author

zhengjinke2123 

分析:用优先队列进行贪心。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>#include <queue>using namespace std;const int maxn = 100000+100;struct node{long long x,y;friend bool operator < (node a,node b){if(a.y==b.y) return a.x<b.x;return a.y>b.y;}}p[maxn],q;bool cmp(const node a,const node b){if(a.x==b.x) return a.y<b.y;return a.x<b.x; }int main(void){int n;while(scanf("%d",&n)!=EOF){int cnt=0;priority_queue<node>que;for(int i=0;i<n;i++)scanf("%lld%lld",&p[i].x,&p[i].y);sort(p,p+n,cmp);        q.y=p[0].y;que.push(q);for(int i=1;i<n;i++){            if(que.top().y>p[i].x) cnt++;             else que.pop();            q.y=p[i].y;            que.push(q);}printf("%d\n",cnt);}return 0;}


1008毛线数列最值

Problem Description

halfyarn找你写个简单的题?好哒!给你n个整数,现在要求你选择两个位置的数,例如选择第pos_a个数a,和第pos_b个数b,给定ans=min(a,b)*abs(pos_a-pos_b),输出ans的最大值。

Input

第一行输入一个n代表有n个数,接下来的一行输入n个整数;
2<=n<=1e6;
1<=a,b<=1e6;
注意多组输入;

Output

ans的最大值;

Sample Input

41 2 2 2

Sample Output

4

Author

zhengjinke2123
 
分析:这题要感谢住辉大大!没有住辉大大的话我写不出,思想很不错,涨姿势了。
           住辉大大原话:首先要先记录位置和值,然后按值从小到大排序,然后从后到前直接维护最大最小距离,每次从前往后更新答案,因为你按值从小到大排序之后,只关注            后面的距离就行了。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;const int maxn = 1e6+10;struct node{long long int num; int mark;}p[maxn];int b[maxn],c[maxn];long long ma,temp;bool cmp(const node a,const node b){    if(a.num==b.num) return a.mark<b.mark;    return a.num<b.num;}void init(){    ma=-1;    memset(b,0,sizeof(b));    memset(c,0,sizeof(c));}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {    init();        for(int i=1;i<=n;i++)        {            scanf("%lld",&p[i].num);            p[i].mark=i;        }        sort(p+1,p+1+n,cmp);        b[n]=c[n]=p[n].mark;        for(int i=n-1;i>=1;i--)        {            if(p[i].mark>b[i+1]) b[i]=p[i].mark;            else b[i]=b[i+1];            if(p[i].mark<c[i+1]) c[i]=p[i].mark;            else c[i]=c[i+1];        }        for(int i=1;i<=n-1;i++)        {            temp=max(fabs(p[i].mark-b[i+1]),fabs(p[i].mark-c[i+1]));            ma=max(ma,temp*p[i].num);        }        printf("%lld\n",ma);    }    return 0;}

1009华盛顿洗衣服

Problem Description

华盛顿在寝室洗衣服,遭到了xyf的嫌弃,于是xyf出了道题给华盛顿来做(然而并没有什么关系-v-!)
xyf扔给华盛顿n个字符串,这些字符串的长度不超过10000并且没有空串。有Q个询问,每个询问一个k,求出这n个字符串中的子串包含了第k个字符串的个数(详情请看hint)

Input

多组测试。
每组测试先输入n,Q表示n个字符串,Q个询问。(1<= n ,Q <=1e4)
接下来n行每行一个字符串si,(1<= |si| <= 1e4)
再接下来Q行询问,每个询问输入一个整数k (1<=k<=n)
可以告诉你 一组询问中 ∑(si) <= 5e4;

Output

每次询问输出一个答案,占一行,表示包含了这第k个字符串的个数。

Sample Input

5 5aababababababb12345

Sample Output

43214Hint第一个询问了 k=1,给出的5个字符串中包含第k个字符串的有{1,2,3,4}第一个询问了 k=2,给出的5个字符串中包含第k个字符串的有{2,3,4}第一个询问了 k=3,给出的5个字符串中包含第k个字符串的有{3,4}第一个询问了 k=4,给出的5个字符串中包含第k个字符串的有{4}第一个询问了 k=5,给出的5个字符串中包含第k个字符串的有{2,3,4,5}

Author

zhengjinke2123 

分析:AC自动机。数据弱的问题吧,不然我不可能水过去。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;char s[10010][10010];int main(void){int n,Q;while(scanf("%d%d",&n,&Q)!=EOF){for(int i=1;i<=n;i++)    scanf("%s",s[i]);while(Q--){int x;scanf("%d",&x);int cnt=0;for(int i=1;i<=n;i++){if(strstr(s[i],s[x])) cnt++;}cout<<cnt<<endl;} }return 0;}

1010LB的阶乘

Problem Description

LB是个十分喜欢钻研的人,对什么事都要搞明白。有一天他学习到了阶乘,他十分喜欢,所以他在想一个问题。如果给定一个数n,求n!能不能被2016整除。LB算了好久都没有算出来,所以他向你求助,你能不能帮他解决这个问题呢?

Input

第一行只包含一个整数T(T≤1000),表示测试用例的个数。
对于每个测试用例,第一行只包含一个整数N(0≤N≤10000),N如描述所示。

Output

对于每个测试用例,输出一行,如果N!能被2016整除输出"YES"(不带引号),如果不能输出"NO"(不带引号)。

Sample Input

12016

Sample Output

YES

Author

zhengjinke2123 

分析:暴力。

/*分析:这是我当时写的愚蠢做法,想的太复杂了。      其实可以想的更加简单。 */#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;const int mod = 2016;long long memo[100010];long long fact(long long n){if(n==1||n==0) return 1;if(memo[n]!=0) return memo[n]%mod;return memo[n]=((fact(n-1)%mod)*(n%mod))%mod;}bool check(long long n){if(fact(n)%mod==0) return 1;else return 0;}int main(void){int T;scanf("%d",&T);while(T--){long long int n;scanf("%lld",&n);if(check(n)) puts("YES");else puts("NO");}return 0;}

/*分析:感谢泽明大大的提醒  做法可以更加简单       直接判断n是否大于等于8就行了 因为8!%2016==0*/#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>#include <vector>using namespace std;int main(void){int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);if(n>=8) puts("YES");else puts("NO");}return 0;}



1 0
原创粉丝点击