个人赛

Friend

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2240    Accepted Submission(s): 1122

Problem Description

Friend number are defined recursively as follows.
(1) numbers 1 and 2 are friend number;
(2) if a and b are friend numbers, so is ab+a+b;
(3) only the numbers defined in (1) and (2) are friend number.
Now your task is to judge whether an integer is a friend number.

Input

There are several lines in input, each line has a nunnegative integer a, 0<=a<=2^30.

Output

For the number a on each line of the input, if a is a friend number, output “YES!”, otherwise output “NO!”.

Sample Input

3 13121 12131

Sample Output

YES! YES! NO!

题解:找了半天规律还是没照出来。。。

代码:

 1 #include<stdio.h>
 2 int main(){
 3     int n;
 4     while(~scanf("%d",&n)){
 5                            if(!n){puts("NO!");continue;}
 6                            n++;
 7                            while(n%2==0||n%3==0){
 8                                                  if(!(n%2))n/=2;
 9                                                  else n/=3;
10                                                  }
11                                                  n==1?puts("YES!"):puts("NO!");
12                            }
13     return 0;}

Problem A

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 71   Accepted Submission(s) : 11

Problem Description

In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.

Input

Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.

Output

For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle.

Sample Input

2 8 12 100 200

Sample Output

3 171 2731 845100400152152934331135470251 1071292029505993517027974728227441735014801995855195223534251

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define MAX(x,y)(x>y?x:y)
 4 const int MAXN=10010;
 5 char c[MAXN];
 6 char dp[501][MAXN];
 7 void bignum(char *a,char *b){
 8     int A[MAXN],B[MAXN],C[MAXN];
 9     memset(A,0,sizeof(A));memset(B,0,sizeof(B));
10     memset(C,0,sizeof(C));
11     int t1=strlen(a),t2=strlen(b);
12     for(int i=0,j=t1-1;j>=0;i++,j--)A[i]=a[j]-‘0‘;
13     for(int i=0,j=t2-1;j>=0;i++,j--)B[i]=b[j]-‘0‘;
14     int t=MAX(t1,t2);
15     for(int i=0;i<t;i++){
16         C[i]=A[i]+B[i]+C[i];
17         if(C[i]>9)C[i]-=10,C[i+1]++;
18         if(C[t])t++;
19     }
20     int i,j;
21     for(i=0,j=t-1;j>=0;i++,j--){
22         c[i]=C[j]+‘0‘;
23     }
24     c[i]=‘\0‘;
25 }
26 int main(){
27     dp[0][0]=‘1‘;dp[0][1]=‘\0‘;
28     dp[1][0]=‘1‘;dp[1][1]=‘\0‘;
29     dp[2][0]=‘3‘;dp[2][1]=‘\0‘;
30 /*    char a[1010],b[1010];
31     while(1){
32     scanf("%s%s",a,b);
33     bignum(a,b);
34     printf("%s\n",c);}*/
35     memset(c,0,sizeof(c));
36     for(int i=3;i<=500;i++){
37         bignum(dp[i-2],dp[i-2]);
38         bignum(c,dp[i-1]);
39         strcpy(dp[i],c);
40     }
41     int n;
42     while(~scanf("%d",&n)){
43         printf("%s\n",dp[n]);
44     }
45     return 0;
46 }

Problem A

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 76   Accepted Submission(s) : 17

Problem Description

People are different. Some secretly read magazines full of interesting girls‘ pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this market segment was so far underestimated and that there is lack of such games. This kind of game was thus included into the KOKODáKH. The rules follow:

Each player chooses two numbers Ai and Bi and writes them on a slip of paper. Others cannot see the numbers. In a given moment all players show their numbers to the others. The goal is to determine the sum of all expressions AiBi from all players including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players‘ experience it is possible to increase the difficulty by choosing higher numbers.

You should write a program that calculates the result and is able to find out who won the game.

Input

The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 <= M <= 45000). The sum will be divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time.

Output

For each assingnement there is the only one line of output. On this line, there is a number, the result of expression

(A1B1+A2B2+ ... +AHBH)mod M.

Sample Input

3 16 4 2 3 3 4 4 5 5 6 36123 1 2374859 3029382 17 1 3 18132

Sample Output

2 13195 13

代码:

#include<stdio.h>
int M;
int quik(int a,int b){
    int x=1;
    while(b){
        if(b&1)x*=a;
        if(x>=M)x%=M;
        if(a>=M)a%=M;
        a*=a;
        if(a>=M)a%=M;
        b>>=1;
    }
    return x;
}
int main(){
    int Z,H,a,b;
    scanf("%d",&Z);
    while(Z--){
        int sum=0;
        scanf("%d%d",&M,&H);
        while(H--){
            scanf("%d%d",&a,&b);
            sum+=quik(a,b);

            if(sum>=M)sum%=M;
        }
        printf("%d\n",sum);
    }
    return 0;
}

Problem D

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 96   Accepted Submission(s) : 51

Problem Description

XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns are numbered from 0 to N-1 and XiaoY lives in the town numbered ’0’. There are some directed roads connecting them. It is guaranteed that you can reach any town from the town numbered ’0’, but not all towns connect to each other by roads directly, and there is no ring in this city. One day, XiaoY want to go to the seaside, he asks you to help him find out the shortest way.

Input

There are several test cases. In each cases the first line contains an integer N (0<=N<=10), indicating the number of the towns. Then followed N blocks of data, in block-i there are two integers, Mi (0<=Mi<=N-1) and Pi, then Mi lines followed. Mi means there are Mi roads beginning with the i-th town. Pi indicates whether the i-th town is near to the sea, Pi=0 means No, Pi=1 means Yes. In next Mi lines, each line contains two integers S[sub]Mi[/sub] and L[sub]Mi[/sub], which means that the distance between the i-th town and the S[sub]Mi[/sub] town is L[sub]Mi[/sub].

Output

Each case takes one line, print the shortest length that XiaoY reach seaside.

Sample Input

5 1 0 1 1 2 0 2 3 3 1 1 1 4 100 0 1 0 1

Sample Output

2

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define MAX(x,y)(x>y?x:y)
 4 #define MIN(x,y) (x<y?x:y)
 5 const int INF=0x3f3f3f3f;
 6 const int MAXN=15;
 7 const int MAXM=2010;
 8 struct Edge{
 9     int u,v,w;
10 };
11 Edge edg[MAXM];
12 int dis[MAXN];
13 int N,M,top;
14 bool Bellman(int sx){
15     memset(dis,INF,sizeof(dis));
16     dis[sx]=0;
17     int u,v,w;
18     for(int i=0;i<=N;i++){
19         for(int j=0;j<top;j++){
20             u=edg[j].u;v=edg[j].v;w=edg[j].w;
21             dis[v]=MIN(dis[v],dis[u]+w);
22         }
23     }
24 }
25 int main(){
26     int yon,a,b;
27     while(~scanf("%d",&N)){
28         top=0;
29         for(int i=0;i<N;i++){
30             scanf("%d%d",&M,&yon);
31             if(yon){
32                 edg[top].u=i;edg[top].v=N;edg[top++].w=0;
33                 edg[top].u=N;edg[top].v=i;edg[top++].w=0;
34             }
35             for(int j=0;j<M;j++){
36                 scanf("%d%d",&a,&b);
37                 edg[top].u=i;edg[top].v=a;edg[top++].w=b;
38                 edg[top].u=a;edg[top].v=i;edg[top++].w=b;
39             }
40         }
41         Bellman(0);
42         printf("%d\n",dis[N]);
43     }
44     return 0;
45 }

Problem G

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 512000/512000K (Java/Other)
Total Submission(s) : 145   Accepted Submission(s) : 13

Problem Description

"Guanxi" is a very important word in Chinese. It kind of means "relationship" or "contact". Guanxi can be based on friendship, but also can be built on money. So Chinese often say "I don‘t have one mao (0.1 RMB) guanxi with you." or "The guanxi between them is naked money guanxi." It is said that the Chinese society is a guanxi society, so you can see guanxi plays a very important role in many things.

Here is an example. In many cities in China, the government prohibit the middle school entrance examinations in order to relief studying burden of primary school students. Because there is no clear and strict standard of entrance, someone may make their children enter good middle schools through guanxis. Boss Liu wants to send his kid to a middle school by guanxi this year. So he find out his guanxi net. Boss Liu‘s guanxi net consists of N people including Boss Liu and the schoolmaster. In this net, two persons who has a guanxi between them can help each other. Because Boss Liu is a big money(In Chinese English, A "big money" means one who has a lot of money) and has little friends, his guanxi net is a naked money guanxi net -- it means that if there is a guanxi between A and B and A helps B, A must get paid. Through his guanxi net, Boss Liu may ask A to help him, then A may ask B for help, and then B may ask C for help ...... If the request finally reaches the schoolmaster, Boss Liu‘s kid will be accepted by the middle school. Of course, all helpers including the schoolmaster are paid by Boss Liu.

You hate Boss Liu and you want to undermine Boss Liu‘s plan. All you can do is to persuade ONE person in Boss Liu‘s guanxi net to reject any request. This person can be any one, but can‘t be Boss Liu or the schoolmaster. If you can‘t make Boss Liu fail, you want Boss Liu to spend as much money as possible. You should figure out that after you have done your best, how much at least must Boss Liu spend to get what he wants. Please note that if you do nothing, Boss Liu will definitely succeed.

Input

There are several test cases. For each test case: The first line contains two integers N and M. N means that there are N people in Boss Liu‘s guanxi net. They are numbered from 1 to N. Boss Liu is No. 1 and the schoolmaster is No. N. M means that there are M guanxis in Boss Liu‘s guanxi net. (3 <=N <= 30, 3 <= M <= 1000) Then M lines follow. Each line contains three integers A, B and C, meaning that there is a guanxi between A and B, and if A asks B or B asks A for help, the helper will be paid C RMB by Boss Liu. The input ends with N = 0 and M = 0. It‘s guaranteed that Boss Liu‘s request can reach the schoolmaster if you do not try to undermine his plan.

Output

For each test case, output the minimum money Boss Liu has to spend after you have done your best. If Boss Liu will fail to send his kid to the middle school, print "Inf" instead.

Sample Input

4 5 1 2 3 1 3 7 1 4 50 2 3 4 3 4 2 3 2 1 2 30 2 3 10 0 0

Sample Output

50 Inf

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define MAX(x,y)(x>y?x:y)
 4 #define MIN(x,y) (x<y?x:y)
 5 const int INF=0x3f3f3f3f;
 6 const int MAXN=40;
 7 const int MAXM=2010;
 8 struct Edge{
 9     int u,v,w;
10 };
11 Edge edg[MAXM];
12 int dis[MAXN];
13 int N,M,top;
14 bool Bellman(int sx,int sy){
15     memset(dis,INF,sizeof(dis));
16     dis[sx]=0;
17     int u,v,w;
18     for(int i=1;i<=N;i++){
19         if(i==sy)continue;
20         for(int j=0;j<top;j++){
21             u=edg[j].u;v=edg[j].v;w=edg[j].w;
22             if(u==sy||v==sy)continue;
23             dis[v]=MIN(dis[v],dis[u]+w);
24         }
25     }
26     if(dis[N]==INF)return false;
27     else return true;
28 }
29 int main(){
30     while(~scanf("%d%d",&N,&M),N||M){
31         int a,b,c,flot;
32         top=0;
33         flot=1;
34         while(M--){
35             scanf("%d%d%d",&a,&b,&c);
36             edg[top].u=a;edg[top].v=b;edg[top++].w=c;
37             edg[top].u=b;edg[top].v=a;edg[top++].w=c;
38         }
39         int ans=0;
40         for(int i=2;i<N;i++){
41             if(!Bellman(1,i)){
42                 flot=0;
43                 break;
44             }
45             else ans=MAX(dis[N],ans);
46         }
47         if(flot)printf("%d\n",ans);
48         else puts("Inf");
49     }
50     return 0;
51 }
时间: 2024-10-29 19:09:37

个人赛的相关文章

5.1个人赛解题报告(区间dp,按位与或,图论等水题)

这次5.1打了一场个人赛,已经连赛了三周了,有点疲惫感觉,可能自己太水了,每次都有点小紧张. 这次只解出来三道题,然而有一道按位与按位或的水题不知道思路实在是做题太少,还有就是第一题区间DP,也消耗了不少的时间,但是没有成功的写出来,还是不够熟练啊. 下面写报告 A. System Administrator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

丘成桐大学生数学竞赛2010年分析与方程个人赛试题参考解答

1 (1)Let {xk}nk=1?(0,π) , and define x=1n∑k=1nxi. Show that ∏k=1nsinxkxk≤(sinxx)n. Proof. Direct computations show (lnsinxx)′′=(lnsinx?lnx)′′=?1sin2x+1x2<0, for all x∈(0,π) . Thus lnsinxx is a concave function in (0,π) . Jensen's inequality then yiel

2014暑期最后一次个人赛

今天这场打的还不错吧,就是开场一个小时就WA在两道水题上了,今天的题总体上比原先的个人赛水多了,有点喜剧性吧,就 像这个一样 ,其实我也挺喜欢听小苹果的,虽然一开始骂这是一首破歌. 今天看到A题CodeForces 205B,好开心,这不是可以用昨天那道ZOJ 2243 treap用线段树解决的方法解决.开心的打完代码, 想着我实在太聪明了,可是,但我提交的时候发现,好吧,我又把一道题复杂话了,WA了,一时找不到bug,去 码CUVA 11452题水题,又WA,后来一开窍,C.A题BUG瞬间找出

[家里蹲大学数学杂志]第297期丘成桐大学生数学竞赛2014年分析与方程个人赛试题

1. 设 $f:\bbR\to \bbR$ 连续, 且满足 $$\bex \sup_{x,y\in\bbR}|f(x+y)-f(x)-f(y)|<\infty, \eex$$ $$\bex \vlm{n}\frac{f(n)}{n}=2014. \eex$$ 试证: $$\bex \sup_{x\in\bbR}|f(x)-2014x|<\infty. \eex$$ 2. 设 $\sed{f_i}_{i=1}^n$ 在单位圆 $D=\sed{z;\ |z|<1}$ 内解析, 在 $\bar

第一次集训个人赛 T1(签到题)

一.题目 Description Wangpeng is good at drawing. Now he wants to say numbers like “521” to his girlfriend through the game draw something. Wangpeng can’t write the digit directly. So he comes up a way that drawing several squares and the total area of s

丘成桐大学生数学竞赛2014年分析与方程个人赛试题第一题另解

以下解答来自华东师大大二学生黄越. 特此说明.

暑假集训-个人赛第四场

ID Origin Title   10 / 52 Problem A SPOJ AMR10A Playground     Problem B SPOJ AMR10B Regex Edit Distance     Problem C SPOJ AMR11C Robbing Gringotts   1 / 14 Problem D SPOJ AMR10D Soccer Teams   0 / 3 Problem E SPOJ AMR10E Stocks Prediction   17 / 19

1112个人赛,最长回文串常见算法讨论

ps.此贴大部分文字与代码来自网上,我只是取长补短整理了下 S=“c a b a”  那么  S' = “a b a c”, 这样的情况下 S和 S‘的最长公共子串是aba.没有错误. 但是当 S=“abacdfgdcaba”, 那么S’ = “abacdgfdcaba”. 这样S和S‘的最长公共子串是abacd.很明显abacd并不是S的最长回文子串,它甚至连回文都不是. 现在是不是都明白为什么最长回文子串不能转化成为最长公共子串问题了.当原串S中含有一个非回文的串的反序串的时候,最长公共子串

2015暑假训练赛个人赛(8.5)

  ID Origin Title   96 / 114 Problem A UVALive 4167 Parity  水题1 60 / 124 Problem B UVALive 4168 Lampyridae Teleportae  水题3 3 / 11 Problem C UVALive 4169 Hex Tile Equations   17 / 41 Problem D UVALive 4170 The Bridges of San Mochti   16 / 36 Problem E