UCF Local Programming Contest 2013

直到今天的比赛出现了好多原题,我才意识到前两天的两场比赛都没有整理… 今天是哪个大学主持的比赛呀,🙄🙄🙄🙄,要闹笑话了 哈哈哈

A. Circles Inside a Square

You have 8 circles of equal size and you want to pack them inside a square. You want to minimize the size of the square. The following figure illustrates the minimum way of packing 8 circles inside a square
在这里插入图片描述

The Problem:

Given the radius, r, find the area of the minimum square into which 8 circles of that radius can be packed.

The Input:

The first input line contains a positive integer, n, indicating the number of test cases. Each test case consists of a positive real number (between 0.001 and 1000, inclusive) in a single line denoting the radius, r.

The Output:

For each test case, output the area of the minimum square where 8 circles of radius r can be packed. Print 5 digits after the decimal. Your output is considered correct if it is within ±0.00001 of the judge’s output.

样例输入复制
2
0.1
0.2
样例输出复制
0.34383
1.37532

原题 加了T组测试

#include <bits/stdc++.h>
using namespace std;

int main() {
    int T; scanf("%d", &T);
    while(T--){
    double r, t, s; scanf("%lf", &r); 
     t = 2 * ( (1 + sqrt(2) + sqrt(3)) * r );

     s = t * t / 2;

    printf("%.5lf\n", s);
    }
    return 0;
}

D. Come Minion!

Welcome treasure hunter! I am the great and powerful interplanetary ninja and you are my minion. We must hurry to save this planet from the evil, “Dialog Not Found”. We must travel across the land so that I may prevent “Dialog Not Found” from their evil plans. Also just so you know, minion, I am unable to triumph over a great many trials. Some of these include being looked at, handshakes, and even stairs.

The Problem:

Given a map of locations, routes between locations, and the trials which exist along routes, help the interplanetary ninja reach their target. You must avoid any of the trials that the ninja is unable to triumph over. Then tell the interplanetary ninja if they are able to reach their target and save the world.

The Input:

The first input line contains a positive integer, m, indicating the number of maps to check. Each map will start with an integer on a new line, t (0 ≤ t ≤ 50), that describes the number of trials that the ninja is unable to accomplish. On the next t lines these trials are listed, one per line. The following line will contain two integers, n (2 ≤ n ≤ 30) and e (0 ≤ e ≤ 500). n indicates the number of locations on the map (numbered 0 through n-1) and e indicates the total number of routes between locations on the map. Assume the ninja’s starting location number is 0 and the ninja’s target location is n-1.The following e lines each describe a route between a pair of locations, and the trial on that route. These lines will consist of two integers La and Lb and a string Q. The ninja can travel between location La and location Lb, or between Lb and La, as long as he does not have the trial (Q) on that route. For example, if ninja has the trial “xyz” and the route also has the trial “xyz”, then ninja cannot travel on that route. Assume that there is at most one route between any two locations and exactly one trial for a route.All locations are numbered from 0 to n-1, inclusive. All trials are named using only lowercase letters, 1 to 20 in length. If a trial is not on the “unable to accomplish” list of ninja, then the ninja will be able to accomplish it. Successive values on a line are separated by exactly one space. There are no leading or trailing spaces on any line.

The Output:

For each map, output a line that contains only a 1 if the ninja can reach his target and a 0 if the ninja is unable to reach his target. Each answer must be on a separate line.

样例输入复制
2
3
stairs
talking
staring
4 5
0 3 talking
0 1 abc
0 2 xyz
1 3 stairs
2 3 staring
3
fire
water
people
4 5
0 1 abc
0 2 water
1 2 fire
1 3 xyz
2 3 abc
样例输出复制
0
1

题目大意:
先出一些不能走的路,然后给出一些路的起点、终点,最后问能不能从0
到达m-1位置

// 我的Bug代码  我的思路是把所有的边按照左端点排个序
//  然后搜索就行了  尽可能向右端去扩展
// 然而官方题解给的是并查集   当时我还在考场上推翻了队友的并查集做法    因为我看一分能A的并查集代码  只把左右端点合并
// 但是这样的话   有些后面的边的左端点在这条边的中间  好像就合并不了了
// 还是老样子  评论区 指点
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
#define Maxn 505
using namespace std;

struct Edge{ int a,b;  }e[Maxn];
string ban[Maxn];
int n,m,tot,tag,num;

inline bool cmp(Edge A,Edge B) {
    if(A.a == B.a) return A.b < B.b;
    else return A.a < B.a;
}

inline bool judge_ban(string s) {
    for(int i=1; i<=n; i++)
        if(s == ban[i]) return 1;
    return 0;
}

void DFS(int k,int pos) {
    if(pos >= m - 1) { tag = 1; return ; }
    for(int i=k+1; i<=num; i++) {
        if(e[k].b >= e[i].a && e[i].b > e[k].b) { DFS(i,e[i].b); if(tag == 1) return; }
    }
    if(tag) return ;
}

int main(int argc,char* argv[]) {
    //ios::sync_with_stdio(false);
    int T;   scanf("%d",&T);
    string s;
    while(T--) {
        scanf("%d",&n);
        for(int i=1; i<=n; i++) cin >> ban[i];
        scanf("%d %d",&m,&tot);
        num = 0;
        for(int a,b,i=1; i<=tot; i++) {
            cin >> a >> b >> s;
            if(judge_ban(s)) continue;
            num++;
            e[num].a = a,e[num].b = b;
        }
        sort(e + 1,e + num + 1,cmp);
        tag = 0;
        
        for(int i=1; i<=num; i++) {
        	if(e[i].a == 0) DFS(i,0);
        	if(tag) break;
		}
        printf("%d",tag);
        if(T) printf("\n");
    }
    return 0;
}
// 我的Bug代码  我的思路是把所有的边按照左端点排个序
//  然后搜索就行了  尽可能向右端去扩展
// 然而官方题解给的是并查集   当时我还在考场上推翻了队友的并查集做法    因为我看一分能A的并查集代码  只把左右端点合并
// 但是这样的话   有些后面的边的左端点在这条边的中间  好像就合并不了了
/*#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
#define Maxn 505
using namespace std;

struct Edge{ int a,b;  }e[Maxn];
string ban[Maxn];
int n,m,tot,tag,num;

inline bool cmp(Edge A,Edge B) {
    if(A.a == B.a) return A.b < B.b;
    else return A.a < B.a;
}

inline bool judge_ban(string s) {
    for(int i=1; i<=n; i++)
        if(s == ban[i]) return 1;
    return 0;
}

void DFS(int k,int pos) {
    if(pos >= m - 1) { tag = 1; return ; }
    for(int i=k+1; i<=num; i++) {
        if(e[k].b >= e[i].a && e[i].b > e[k].b) { DFS(i,e[i].b); if(tag == 1) return; }
    }
    if(tag) return ;
}

int main(int argc,char* argv[]) {
    //ios::sync_with_stdio(false);
    int T;   scanf("%d",&T);
    string s;
    while(T--) {
        scanf("%d",&n);
        for(int i=1; i<=n; i++) cin >> ban[i];
        scanf("%d %d",&m,&tot);
        num = 0;
        for(int a,b,i=1; i<=tot; i++) {
            cin >> a >> b >> s;
            if(judge_ban(s)) continue;
            num++;
            e[num].a = a,e[num].b = b;
        }
        sort(e + 1,e + num + 1,cmp);
        tag = 0;
        
        for(int i=1; i<=num; i++) {
        	if(e[i].a == 0) DFS(i,0);
        	if(tag) break;
		}
        printf("%d",tag);
        if(T) printf("\n");
    }
    return 0;
} */
//  AC 代码
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#define  Maxn 505
using namespace std;
string ban[Maxn];
int fx[Maxn];

int Find(int x) {
    if(fx[x] == x) return x;
    else return fx[x] = Find(fx[x]);
}

void Union(int a,int b) {
    int fa = Find(a),fb = Find(b);
    if(fa != fb) fx[fa] = fb;
}

int main(int argc,char* argv[]) {
    int T,t,n,e; scanf("%d",&T);
    while(T--) {
        scanf("%d",&t);
        for(int i=1; i<=t; i++) cin >> ban[i];
        scanf("%d %d",&n,&e);
        for(int i=0; i<=n; i++) fx[i] = i;
        for(int i=1; i<=e; i++) {
            int a,b,flag = 0;
            string s;
            cin >> a >> b >> s;
            for(int j=1; j<=t; j++) if(ban[j] == s) { flag = 1; break; }
            if(flag) continue;
            Union(a,b);
        }
        if(Find(0) == Find(n - 1)) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

E. Jumping Frog

A frog is located at the coordinate (x1,y1). He wants to go to the coordinate (x2,y2). He will perform one or more jumps to reach his destination. The rule of the jumping is as follows: Suppose the frog is located at the coordinate (x,y); then he can jump to the following foursquares:

  1. (x+y,y)

  2. (x-y,y)

  3. (x,y+x)

  4. (x,y-x)

The Problem:

Given the coordinates (x1,y1) and (x2,y2), you need to determine if it is possible for the frog to travel from (x1,y1) to (x2,y2) through a series of jumps as described.

The Input:

The first input line contains an integer, n (1 ≤ n ≤ 100), indicating the number of test cases. Each test case consists of four integers (between -1,000,000,000 to +1,000,000,000 inclusive) separated by a single space denoting x1, y1, x2 and y2, respectively.

The Output:

For each test case, output 1 if the frog can travel from (x1,y1) to (x2,y2) through a series of jumps as described or 0 otherwise.

样例输入复制
3
-6 8 17 25
13 17 -16 11
0 0 5 6
样例输出复制
0
1
0

题目分析:
如果可以起点和终点都能到达同一的点它们就能相互到达。
模拟一下移动规则可知,(x,y)可以到达(y,x)
再观察操作本质上是辗转相除法。
(x,y)->(x-k*y,y)->(x%y,y)->(y,y%x)
因此只要起点终点分别做一遍gcd看看是否相等即可。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int gcd(int a,int b) {
    if(b == 0) return a;
    else return gcd(b,a % b);
}

int main(int argc,char* argv[]) {
    int T; scanf("%d",&T);
    while(T--) {
        long long x1,x2,y1,y2;
        scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);
        if(gcd(abs(x1),abs(y1)) == gcd(abs(x2),abs(y2))) printf("1\n");
        else printf("0\n");
    }

    return 0;
}

G. Buying in Bulk

To encourage customers to shop more, some stores charge lower prices if you buy multiples of an item. For example, if you buy one, it may cost you 5 but if you buy two, it will cost you5butifyoubuytwo,itwillcostyou8 instead of $10.

The Problem:

Let’s assume a store provides discounts as follows:1. No discount if you buy only one.2. $2 discount for each additional item if you buy more than one.Given the number of items a customer has purchased and the price for one item, you are to compute the total cost for the customer.

The Input:

The first input line contains a positive integer, n, indicating the number of customers to check. The customers are on the following n input lines, one customer per line. Each line provides two integers; the first integer c (1 ≤ c ≤ 100) is the number of items purchased by the customer, and the second integer p (3 ≤ p ≤ 50) is the price for one item.

The Output:

For each customer, print two lines of output. The first line will contain the two input values separated by a single space. The second output line will contain the total cost for the customer. There should be no leading or trailing spaces on any output line.

样例输入复制
2
1 5
3 10
样例输出复制
1 5
5
3 10
26

#include<cstdio>

using namespace std;

int main(int argc,char* argv[]) {
    int T; scanf("%d",&T);
    while(T--) {
        int n, m;
        scanf("%d %d", &n, &m);
        printf("%d %d\n",n,m);
        printf("%d\n", n * m - 2 * (n - 1));
    }

K. Are We Stopping Again?

Going on a road trip is an adventure for Dr. Orooji and his family. Obviously he has to stop torefuel the car, but he also stops whenever his kids want to eat. Dr. O needs to figure out the number of stops before going on the trip so he is mentally prepared.

The Problem:

Find the total number of stops for Dr. O’s trip, given:

  1. Total miles to be traveled.

  2. How often he stops for gas (in miles).

  3. How often he stops for food (in miles).

Assume that the car’s gas tank is full at the beginning of the trip and the kids are full as well. If the destination happens to be the time to refuel (or eat), do not count it as a stop. Also, if a particular mileage happens to be both refueling time and eating time, count it as one stop and not two stops.Note that if a particular mileage happens to be refueling time only, kids won’t eat at that stop. Similarly, if a particular mileage happens to be eating time only, the car is not refueled at that stop.

The Input:

The first input line contains a positive integer, t, indicating the number of trips to check. The trips are on the following t input lines, one trip per line. Each trip provides three integers (each between 1 and 1000, inclusive); these are the three values specified in order above.

The Output:

For each trip, output the three input values. Then, on the next output line, print the number of stops for the trip.

样例输入复制
3
100 30 40
10 5 1
20 3 4
样例输出复制
100 30 40
5
10 5 1
9
20 3 4
9

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int gcd(int a,int b) {
	if(b == 0) return a;
	else return gcd(b,a % b);
}
int main(int argc,char* argv[]) {
	int n,m,k,T; scanf("%d",&T);
	while(T--) {
		scanf("%d %d %d",&n,&m,&k);
		printf("%d %d %d\n",n,m,k);
		printf("%d\n",(n - 1) / m + (n - 1) / k - (n -1) / (m * k / gcd(m,k)));	
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值