A. Line to Cashier
l链接:http://codeforces.com/contest/408/problem/A
描述:求最小等待时间,直接模拟以后取最小值即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
//const int M = 10000;
int main()
{
int n, val, num;
while (scanf("%d", &n) != EOF) {
int a[n];
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
vector<int> t;
for (int i = 0; i < n; ++i) {
num = a[i];
int sum = 0;
for (int j = 0; j < a[i]; ++j) {
scanf("%d", &val);
sum += val;
}
sum *= 5;
sum += 15 * num;
t.push_back(sum);
}
printf("%d\n", *min_element(t.begin(), t.end()));
}
return 0;
}
B. Garland
链接:http://codeforces.com/contest/408/problem/B
描述:题目意思一开始没读懂。实际上就是由上面的字符串去构造下面的,每一个字母代表一种颜色 ,面积为1平方的纸张(可以裁剪)。求最大去构造下面字母的面积,如果不能的话,就输出-1.
思路:直接模拟。一开始需要判断是不是第二个字符串中出现的字母在第一个字符串中都有出现,若不是肯定无法构造。输出-1.否则只需要统计字符串中每个字母出现的次数,累加较小值即可。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
string s1, s2;
while (cin >> s1 >> s2) {
int len1 = s1.size(), len2 = s2.size();
int i = 0, j = 0, ans = 0;
int t1[30] = {0}, t2[30] = {0};
for (int i = 0; i < len1; ++i)
t1[s1[i]-'a']++;
for (int i = 0; i < len2; ++i)
t2[s2[i]-'a']++;
int sum = 0;
bool ok = 1;
for (int i = 0; i < 26; ++i)
if (t2[i] != 0 && t1[i] == 0) {
ok = 0;
break;
}
for (int i = 0; i < 27; ++i)
if (t2[i] != 0) {
if (t2[i] <= t1[i])
sum += t2[i];
else
sum += t1[i];
}
if (!ok)
sum = -1;
cout << sum << endl;
}
return 0;
}
C. Triangle
链接:http://codeforces.com/contest/408/problem/C
描述:给定一个直角三角形的两个直角边长a和b(1<=a,b<=1000),求能否找到一个放置三角形的位置,使得该直角三角形的任意一条边都不平行于坐标轴,且三个顶点的坐标都是整数。
思路:由于a和b都不大,所以暴力枚举即可。固定三角形的直角顶点在(0, 0),对于a和b分别枚举,需要满足相似三角形原理,所以s1*l1 == s2*l2,并且s2 != l2,否则平行于x轴了。最后的答案就是(0,0) (-s1, s2) (l1, l2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
struct T1 {
int s1, s2;
};
struct T2 {
int l1, l2;
};
int main()
{
int a, b;
while (scanf("%d %d", &a, &b) != EOF) {
vector<T1> avec;
vector<T2> bvec;
for (int i = 1; i < a; ++i)
for (int j = 1; j < a; ++j)
if (i*i + j*j == a*a)
avec.push_back((T1){i, j});
for (int i = 1; i < b; ++i)
for (int j = 1; j < b; ++j)
if (i*i + j*j == b*b)
bvec.push_back((T2){i, j});
bool ok = 0;
int s1, s2, l1, l2;
for (int i = 0; i < avec.size(); ++i)
for (int j = 0; j < bvec.size(); ++j)
if (avec[i].s1*bvec[j].l1 == avec[i].s2*bvec[j].l2
&& avec[i].s2 != bvec[j].l2) {
ok = 1;
s1 = avec[i].s1, s2 = avec[i].s2;
l1 = bvec[j].l1, l2 = bvec[j].l2;
break;
}
if (ok)
printf("YES\n0 0\n%d %d\n%d %d\n", -s1, s2, l1, l2);
else
printf("NO\n");
}
return 0;
}