Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki people. The j-th person standing in the queue to the i-th cashier has mi, j items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item;
- after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier.
The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, ..., mi, ki (1 ≤ mi, j ≤ 100) — the number of products the j-th person in the queue for the i-th cash has.
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
1 1 1
20
4 1 4 3 2 100 1 2 2 3 1 9 1 7 8
100
题意:有n个收营员,每个收营员面前有ni个消费者,再给定n行,第i行有ni个数表示每个消费者手里的商品数量,每个收银员扫描一个商品消耗5秒,每个消费者之前间隔15秒,问,收银员花费的最少时间是多少。
思路:emm,直接遍历比较就好。
#include<stdio.h>
const int maxn = 110;
#define inf 0x3f3f3f3f
int k[maxn],num[maxn][maxn];
int main()
{
int n,number;
while(scanf("%d",&n)!=EOF)
{
for(int i = 0; i < n; i ++)
scanf("%d",&k[i]);
int minn = inf;
for(int i = 0; i < n; i ++)
{
int sum = 0;
for(int j = 0; j < k[i]; j ++)
{
scanf("%d",&number);
sum += number*5;
}
k[i] = k[i]*15 + sum;
if(k[i]<minn)
minn = k[i];
}
printf("%d\n",minn);
}
return 0;
}
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.
Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of m pieces of paper in the garland. Calculate what the maximum total area of the pieces of paper in the garland Vasya can get.
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
aaabbac aabbccac
6
a z
-1
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color z
题意:给定两个字符串,只包含a~z的小写字母,问最多匹配的字符串个数,匹配原则是串1和串2都出现的相同字符,匹配字符数+1,如果串2出现了串1没有的字符,输出-1
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 1010;
char str1[maxn],str2[maxn];
int num1[maxn],num2[maxn];
int main()
{
int l1,l2,sum;
while(scanf("%s",str1)!=EOF)
{
scanf("%s",str2);
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
sum = 0;
for(int i = 0; str1[i]!='\0';i++)
num1[str1[i]-'0']++;
for(int i = 0; str2[i]!='\0';i++)
num2[str2[i]-'0']++;
for(int i = 'a'-'0'; i <= 'z'-'0'; i ++)
{
if(num1[i] >= num2[i])
sum += num2[i];
else if(num1[i]<num2[i]&&num1[i]!=0)
{
sum += num1[i];
}
else if(num1[i]<num2[i]&&num1[i]==0)
{
sum = 0;
break;
}
}
if(sum)
printf("%d\n",sum);
else
printf("-1\n");
}
return 0;
}
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
1 1
NO
5 5
YES 2 1 5 5 -2 4
5 10
YES -10 4 -2 -2 1 2
题意:给你一个直角三角形的两条直角边,问是否存在三角形的任意一条边都不平行于直角坐标系且三个顶点坐标都为整数,如果有,输出任意一个三角形的三个顶点的坐标。
思路:由于是任意一个三角形,那假设其中一个顶点在原点,要求三个顶点坐标都是整数,可以将a,b分别作为斜边即a=sqrt(i*i+j*j),b=sqrt(i*i+j*j),枚举找到满足上述式子的坐标点保存,注意,一条边位于x轴负半轴区域,一条边位于x轴正半轴区域,最后,在已经找到的坐标点中遍历查找,满足两点间距离等于斜边的坐标且坐标点不平行于x轴,输出即可
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
const int maxn = 1000;
struct node{
int x,y;
};
int main()
{
int a,b;
struct node vis[maxn],vis2[maxn];
while(scanf("%d%d",&a,&b)!=EOF)
{
double n,m;
int p=0,q=0;
for(int i = 1; i < a; i ++)
{
n = sqrt(a*a-i*i);
if(n - (int)n == 0&&n!=0)
{
vis[p].x = -i;
vis[p++].y = n;
}
}
for(int j = 1; j < b ; j ++)
{
m = sqrt(b*b-j*j);
if(m - (int)m == 0&&m!=0)
{
vis2[q].x = j;
vis2[q++].y = m;
}
}
int flag = 0;
for(int i = 0; i < p; i ++)
{
for(int j = 0; j < q;j++)
{
if(vis[i].y != vis[j].y )
{
int x = a*a+b*b;
int y = (vis[i].x - vis2[j].x)*(vis[i].x - vis2[j].x)+(vis[i].y-vis2[j].y)*(vis[i].y-vis2[j].y);
if(x == y)
{
printf("YES\n");
printf("0 0\n");
printf("%d %d\n",vis[i].x ,vis[i].y );
printf("%d %d\n",vis2[j].x ,vis2[j].y );
flag = 1;
break;
}
}
}
if(flag)
break;
}
if(!flag)
printf("NO\n");
}
return 0;
}