QDU_组队训练(ABEFGHKL)

A - Accurately Say "CocaCola"!

In a party held by CocaCola company, several students stand in a circle and play a game.

One of them is selected as the first, and should say the number 1. Then they continue to count number from 1 one by one (clockwise). The game is interesting in that, once someone counts a number which is a multiple of 7 (e.g. 7, 14, 28, ...) or contains the digit '7' (e.g. 7, 17, 27, ...), he shall say "CocaCola" instead of the number itself.

For example, 4 students play this game. At some time, the first one says 25, then the second should say 26. The third should say "CocaCola" because 27 contains the digit '7'. The fourth one should say "CocaCola" too, because 28 is a multiple of 7. Then the first one says 29, and the game goes on. When someone makes a mistake, the game ends.

During a game, you may hear a consecutive of p "CocaCola"s. So what is the minimum number that can make this situation happen?

For example p = 2, that means there are a consecutive of 2 "CocaCola"s. This situation happens in 27-28 as stated above. 27 is then the minimum number to make this situation happen.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 100) which is the number of test cases. And it will be followed by T consecutive test cases.

There is only one line for each case. The line contains only one integer p (1 <= p<= 99).

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the minimum possible number for the first of the p "CocaCola"s stands for.

Sample Input

2
2
3

Sample Output

27
70

 思维规律题:既然告诉了3的时候是70,然后,4,10都可以在70表示,因为含7,再跑一下别的即可发现除了11,其余都可在700表示出来

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 100005 



typedef long long ll;
using namespace std;
char str[2010];
int a[2010];
int main()
{
	int T;
    while(cin>>T)
    {
    	while(T--)
    	{
    		int n;
    		cin>>n;
    		if(n==1)
    		{
    			cout<<"7"<<endl;
			}
			else if(n==2)
			{
				cout<<"27"<<endl;
			}
			else if(n>=3&&n<=10)
			{
				cout<<"70"<<endl;
			}
			else if(n==11)
			{
				cout<<"270"<<endl;
			}
			else 
			{
				cout<<"700"<<endl;
			}
		}
	}
	return 0;
 } 

B - Build The Electric System

In last winter, there was a big snow storm in South China. The electric system was damaged seriously. Lots of power lines were broken and lots of villages lost contact with the main power grid. The government wants to reconstruct the electric system as soon as possible. So, as a professional programmer, you are asked to write a program to calculate the minimum cost to reconstruct the power lines to make sure there's at least one way between every two villages.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

In each test case, the first line contains two positive integers N and E (2 <= N <= 500, N <= E <= N * (N - 1) / 2), representing the number of the villages and the number of the original power lines between villages. There follow E lines, and each of them contains three integers, ABK (0 <= AB < N, 0 <= K < 1000). A and Brespectively means the index of the starting village and ending village of the power line. If K is 0, it means this line still works fine after the snow storm. If K is a positive integer, it means this line will cost K to reconstruct. There will be at most one line between any two villages, and there will not be any line from one village to itself.

Output

For each test case in the input, there's only one line that contains the minimum cost to recover the electric system to make sure that there's at least one way between every two villages.

Sample Input

1
3 3
0 1 5
0 2 0
1 2 9

Sample Output

5

最小生成树,找了自己之前写的改了一下就ok了

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 100005 

typedef long long ll;
using namespace std;

struct node
{
    int s,t,c;
} ss[40005];
 
int father[605];
 
int cmp(node x,node y)
{
    return x.c<y.c;
}
 
int find(int x)
{
    return father[x]=(father[x]==x?x:find(father[x]));
}
 
int main()
{
    int t,n,m,i,ans;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(i = 0; i<m; i++)
            scanf("%d%d%d",&ss[i].s,&ss[i].t,&ss[i].c);
        for(i = 0; i<n; i++)
            father[i] = i;
        sort(ss,ss+m,cmp);
        ans = 0;
        for(i = 0; i<m; i++)
        {
            int fx = find(ss[i].s);
            int fy = find(ss[i].t);
            if(fx!=fy)
            {
                ans+=ss[i].c;
                father[fx] = fy;
            }
        }
        printf("%d\n",ans);
    }
 
    return 0;
}

E - Easy Task

Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivation. We use x^n to denote xn. To calculate the derivation of a polynomial, you should know 3 rules: 
(1) (C)'=0 where C is a constant. 
(2) (Cx^n)'=C*n*x^(n-1) where n>=1 and C is a constant. 
(3) (f1(x)+f2(x))'=(f1(x))'+(f2(x))'. 

It is easy to prove that the derivation a polynomial is also a polynomial.

Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1000) which is the number of test cases. And it will be followed by T consecutive test cases.

There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integer N (0 <= N <= 100). The second line contains N + 1 non-negative integers, CNCN-1, ..., C1C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x). Ci is the coefficient of the term with degree i in f(x). (CN!=0)

Output

For each test case calculate the result polynomial g(x) also in a single line. 
(1) If g(x) = 0 just output integer 0.otherwise 
(2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+...+C0 (Cm!=0),then output the integers Cm,Cm-1,...C0.
(3) There is a single space between two integers but no spaces after the last integer. 

Sample Input

3
0
10
2
3 2 1
3
10 0 1 2

Sample Output

0
6 2
30 0 1

模拟?反正就是除了等于1的时候,其余只要从×n乘到1就好了,输出n个

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 100005 



typedef long long ll;
using namespace std;
char str[2010];
int a[2010];
int main()
{
	int T;
	int n;
    while(cin>>T)
    {
    	while(T--)
    	{
    		int n;
    		cin>>n;
    		if(n==0)
    		{
    			cin>>a[0];
    			cout<<0<<endl;
			}
			else{
		
    		for(int t=0;t<n+1;t++ )
    		{
    			scanf("%d",&a[t]);
			}
			for(int t=0;t<n;t++)
			{
				if(t!=n-1)
				cout<<a[t]*(n-t)<<" ";
			    else
				{
					cout<<a[t];
				}
			}
			cout<<endl;
			}
    		
        }
	}
	return 0;
 } 

F - Faster, Higher, Stronger

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.

The motto of Olympic Games is "Citius, Altius, Fortius", which means "Faster, Higher, Stronger".

In this problem, there are some records in the Olympic Games. Your task is to find out which one is faster, which one is higher and which one is stronger.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case has 3 lines. The first line is the type of the records, which can only be "Faster" "Higher" or "Stronger". The second line is a positive integer Nmeaning the number of the records in this test case. The third line has N positive integers, i.e. the records data. All the integers in this problem are smaller than 2008.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line. If the type is "Faster", the records are time records and you should output the fastest one. If the type is "Higher", the records are length records. You should output the highest one. And if the type is "Stronger", the records are weight records. You should output the strongest one.

Sample Input

3
Faster
3
10 11 12
Higher
4
3 5 4 2
Stronger
2
200 200

Sample Output

10
5
200

这道题就更不用解释了

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 100005 



typedef long long ll;
using namespace std;
char str[2010];
int a[2010];
int main()
{
	int T;
	while(cin>>T)
	{
	  while(T--)
	  {
	  	cin>>str;
	  	int n;
	  	if(strcmp(str,"Faster")==0)
	  	{
	  		cin>>n;
	  		for(int t=0;t<n;t++)
	  		{
	  		  scanf("%d",&a[t]);	
			}
			sort(a,a+n);
			cout<<a[0]<<endl;
	  		
		}
		else if(strcmp(str,"Higher")==0)
		{
			cin>>n;
	  		for(int t=0;t<n;t++)
	  		{
	  		  scanf("%d",&a[t]);	
			}
			sort(a,a+n);
			cout<<a[n-1]<<endl;
		}
		else
		{
			cin>>n;
	  		for(int t=0;t<n;t++)
	  		{
	  		  scanf("%d",&a[t]);	
			}
			sort(a,a+n);
			cout<<a[n-1]<<endl;
		}
	  }	
	} 
	return 0;
 } 

G - Give Me the Number 

Numbers in English are written down in the following way (only numbers less than 109are considered). Number abc,def,ghi is written as "[abc] million [def] thousand [ghi]". Here "[xyz] " means the written down number xyz .

In the written down number the part "[abc] million" is omitted if abc = 0 , "[def]thousand" is omitted if def = 0 , and "[ghi] " is omitted if ghi = 0 . If the whole number is equal to 0 it is written down as "zero". Note that words "million" and "thousand" are singular even if the number of millions or thousands respectively is greater than one.

Numbers under one thousand are written down in the following way. The number xyz is written as "[x] hundred and [yz] ”. ( If yz = 0 it should be only “[x] hundred”. Otherwise if y = 0 it should be only “[x] hundred and [z]”.) Here "[x] hundred and" is omitted if x = 0 . Note that "hundred" is also always singular.

Numbers under 20 are written down as "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", and "nineteen" respectively. Numbers from 20 to 99 are written down in the following way. Number xy is written as "[x0][y] ", and numbers divisible by ten are written as "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", and "ninety" respectively.

For example, number 987,654,312 is written down as "nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twelve", number 100,000,037 as "one hundred million thirty seven", number 1,000 as "one thousand". Note that "one" is never omitted for millions, thousands and hundreds.

Give you the written down words of a number, please give out the original number.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1900) which is the number of test cases. It will be followed by T consecutive test cases.

Each test case contains only one line consisting of a sequence of English words representing a number.

Output

For each line of the English words output the corresponding integer in a single line. You can assume that the integer is smaller than 109.

Sample Input

3
one
eleven
one hundred and two

Sample Output

1
11
102

用map将数字与字符串对应起来,接着就是模拟这些数就ok了

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 100005 



typedef long long ll;
using namespace std;
map<string,int>mp;
char s[150000];
 
int main()
{
	mp["one"] = 1;mp["two"] = 2;mp["three"] = 3;mp["four"] = 4;mp["five"] = 5;mp["six"] = 6;mp["seven"] = 7;
	mp["eight"] = 8;mp["nine"] = 9;mp["ten"] = 10;mp["eleven"] = 11;mp["twelve"] = 12;mp["thirteen"] = 13;
	mp["fourteen"] = 14;mp["fifteen"] = 15;mp["sixteen"] = 16;mp["seventeen"] = 17;mp["eighteen"] = 18;
	mp["nineteen"] = 19;mp["twenty"] = 20;mp["thirty"] = 30;mp["forty"] = 40;mp["fifty"] = 50;mp["sixty"] = 60;
	mp["seventy"] = 70;mp["eighty"] = 80;mp["ninety"] = 90;
	int T,ans,i,sum;
	string ss;
	cin>>T;
	getchar();
	while(T--)
	{
		sum = 0;
		ans = 0;
		gets(s);
		int len = strlen(s);
		for(i = 0; i <= len; i++)
		{
			if(s[i]!=' '&&s[i]!='\0')
			{
				ss += s[i];
				continue;
			}
			if(ss=="hundred")
			{
				ans *= 100;
			}
			else if(ss=="thousand")
			{
				ans *= 1000;
				sum += ans;
				ans = 0;
			}			
			else if(ss=="million")
			{
				ans *= 1000000;
				sum += ans;
				ans = 0;
			}
			else ans += mp[ss];	
			ss.clear();		
		}
		if(ans != 0)	sum += ans;
		cout<<sum<<endl;
	}
} 

H - Hurdles of 110m

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.

Liu Xiang is one of the famous Olympic athletes in China. In 2002 Liu broke Renaldo Nehemiah's 24-year-old world junior record for the 110m hurdles. At the 2004 Athens Olympics Games, he won the gold medal in the end. Although he was not considered as a favorite for the gold, in the final, Liu's technique was nearly perfect as he barely touched the sixth hurdle and cleared all of the others cleanly. He powered to a victory of almost three meters. In doing so, he tied the 11-year-old world record of 12.91 seconds. Liu was the first Chinese man to win an Olympic gold medal in track and field. Only 21 years old at the time of his victory, Liu vowed to defend his title when the Olympics come to Beijing in 2008.

In the 110m hurdle competition, the track was divided into N parts by the hurdle. In each part, the player has to run in the same speed; otherwise he may hit the hurdle. In fact, there are 3 modes to choose in each part for an athlete -- Fast Mode, Normal Mode and Slow Mode. Fast Mode costs the player T1 time to pass the part. However, he cannot always use this mode in all parts, because he needs to consume F1force at the same time. If he doesn't have enough force, he cannot run in the part at the Fast Mode. Normal Mode costs the player T2 time for the part. And at this mode, the player's force will remain unchanged. Slow Mode costs the player T3 time to pass the part. Meanwhile, the player will earn F2 force as compensation. The maximal force of a player is M. If he already has M force, he cannot earn any more force. At the beginning of the competition, the player has the maximal force.

The input of this problem is detail data for Liu Xiang. Your task is to help him to choose proper mode in each part to finish the competition in the shortest time.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case begins with two positive integers N and M. And following N lines denote the data for the N parts. Each line has five positive integers T1 T2 T3 F1 F2. All the integers in this problem are less than or equal to 110.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the shortest time that Liu Xiang can finish the competition.

Sample Input

2
1 10
1 2 3 10 10
4 10
1 2 3 10 10
1 10 10 10 10
1 1 2 10 10
1 10 10 10 10

Sample Output

1
6

Hint

For the second sample test case, Liu Xiang should run with the sequence of Normal Mode, Fast Mode, Slow Mode and Fast Mode.

dp背包问题

在dp[i][j]数组中,i为第i个障碍,j为目前所拥有的能量,求第一个求跨过N个障碍所需要的最短时间。

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
int dp[150][150];
int f[150][3],val[150][2];
int n,m;

int main(){
	int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(dp,INF,sizeof(dp));
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d%d%d",&f[i][0],&f[i][1],&f[i][2],&val[i][0],&val[i][1]);
		}
		dp[0][m]=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<=m;j++)
			{	
				dp[i][j]=min(dp[i][j],dp[i-1][j]+f[i][1]);
				if(j>=val[i][0])
					dp[i][j-val[i][0]]=min(dp[i][j-val[i][0]],dp[i-1][j]+f[i][0]);	
				int tmp=min(j+val[i][1],m);
				dp[i][tmp]=min(dp[i][tmp],dp[i-1][j]+f[i][2]);
			}
		} 
		int ans=INF;
		for(int i=0;i<=m;i++)
		{
			ans=min(ans,dp[n][i]);
		}
		printf("%d\n",ans);
	}
    return 0;
}

K - Kinds of Fuwas

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China as well as becoming a festival for people all over the world.

The official mascots of Beijing 2008 Olympic Games are Fuwa, which are named as Beibei, Jingjing, Haunhuan, Yingying and Nini. Fuwa embodies the natural characteristics of the four most popular animals in China -- Fish, Panda, Tibetan Antelope, Swallow -- and the Olympic Flame. To popularize the official mascots of Beijing 2008 Olympic Games, some volunteers make a PC game with Fuwa.

As shown in the picture, the game has a matrix of Fuwa. The player is to find out all the rectangles whose four corners have the same kind of Fuwa. You should make a program to help the player calculate how many such rectangles exist in the Fuwa matrix.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

The first line of each test case has two integers M and N (1 <= MN <= 250), which means the number of rows and columns of the Fuwa matrix. And then there are M lines, each has N characters, denote the matrix. The characters -- 'B' 'J' 'H' 'Y' 'N' -- each denotes one kind of Fuwa.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the number of the rectangles whose four corners have the same kind of Fuwa.

按竖行找,遇到竖行相同的就开始横向找,直到找到横向相同的字符,且与该字符同竖向的字符相同,暴力累加

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 100005 



typedef long long ll;
using namespace std;
char str[2010];
char a[505][505];
char b[5]={'B','J','H','Y','N'};
int main()
{
	int T;
	int n;
    while(cin>>T)
    {
    	while(T--)
    	{
    	   int n,m;
    	   cin>>n>>m;
    	   getchar();
    	   for(int t=0;t<n;t++)
    	   {
    	   	scanf("%s",a[t]);
		   }
		   int minn=min(n,m);
		   int s,ss=0;
		   for(int l=0;l<5;l++)
			{
				for(int i=0;i<n;i++)
				{
					for(int j=i+1;j<n;j++ )
					{
						s = 0 ;
						for(int  k=0 ;k<m;k++)
						{
							if( a[i][k] == a[j][k] && a[i][k] == b[l])
							{
								s++;
							}
						}
						ss+= s*(s-1)/2;
					}
				}
			}
		   cout<<ss<<endl;
    		
        }
	}
	return 0;
 } 

L - Light Bulbs

Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and get married this year. He bought a new house for his family and hired a company to decorate his house. Wildleopard and his fiancee were very satisfied with the postmodern design, except the light bulbs. Varieties of light bulbs were used so that the light in the house differed a lot in different places. Now he asks you, one of his best friends, to help him find out the point of maximum illumination.

To simplify the problem, we can assume each bulb is a point light source and we only need to consider the grid points of the flat floor of the house. A grid point is a point whose coordinates are both integers. The length and the width of house can be considered infinite. Illumination means the amount of light that go through in one unit area. The illumination of a point can be calculated by simply adding the illumination from each source. The illumination from a source can be calculated by the following equation:

, where E is the illumination of the point, I is the luminous intensity of the source, R is the distance between the source and the point and i is the angle between the normal of the plane and the light to the point.

Given the position and the luminous intensity of the light bulbs, you are asked to find the maximum illumination on the floor at the grid points.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 20) which is the number of test cases. And it will be followed by T consecutive test cases.

The first line of each test case contains one integer n(1 <= n <= 100), indicating the number of bulbs of the lamps in the house. The next n lines will contain 4 integers each, XiYiZiIi, separated by one space, indicating the coordinates and the luminous intensity of the i-th bulb of the lamp. The absolute values of the coordinates do not exceed 100 and Zi is always positive. Ii is a positive integer less than 32768.

Output

Results should be directed to standard output. The output of each test case should be a real number rounded to 0.01, which is the maximum illumination on the floor at the grid points.

Sample Input

3
1
0 0 1 100
4
1 0 1 100
0 1 1 100
-1 0 1 100
0 -1 1 100
4
1 0 100 10000
0 1 100 10000
-1 0 100 10000
0 -1 100 10000

Sample Output

100.00
147.43
4.00

这题理解了很简单,我一直错在了多组输入上,我用的多组输入就段错误,单租就过了也不太懂为什么

就是枚举这个矩形范围内的点,根据那个公式去求强度最大就行了

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>

typedef long long ll;
using namespace std;

struct node
{
	double x,y,z,l;
}p[10005];


double R(double x,double y,double z,double x1,double y1)
{
	return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)+z*z);
}
int main()
{
	int T;
	cin>>T;
	
	while(T--)
	{
		int n;
		cin>>n;
		for(int t=0;t<n;t++)
		{
			scanf("%lf%lf%lf%lf",&p[t].x,&p[t].y,&p[t].z,&p[t].l);
			
		}
		double ans=0;
		double E;
		double r2;
		double cossi;
		for(int t=-100;t<=100;t++)
		{
			for(int j=-100;j<=100;j++)
			{
				E=0;
				for(int k=0;k<n;k++)
				{
					
				   r2=R(p[k].x,p[k].y,p[k].z,(double)t,(double)j);
				   cossi=(p[k].z)/r2;
				   E+=p[k].l*cossi/(r2*r2);
				 
				}
				ans=max(ans,E);
				
			}
		}
		printf("%.2f\n",ans);
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/lbperfect123/article/details/88090405