LightOJ 1338 && 1387 - Setu && LightOJ 1433 && CodeForces 246B(水题)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:
- You can change some uppercase letters to lower case and vice versa.
- You can add/remove spaces freely.
- You can permute the letters.
And if two names match exactly, then you can say that one name is hidden into another.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with two lines. Each line contains a name consists of upper/lower case English letters and spaces. You can assume that the length of any name is between 1 and 100 (inclusive).
Output
For each case, print the case number and "Yes" if one name is hidden into another. Otherwise print "No".
Sample Input
3
Tom Marvolo Riddle
I am Lord Voldemort
I am not Harry Potter
Hi Pretty Roar to man
Harry and Voldemort
Tom and Jerry and Harry
Sample Output
Case 1: Yes
Case 2: Yes
Case 3: No
判断第一个串是否包含第二个串,可以交换位置,改变大小写。。。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
template<typename T>
bool is_lower(T x){
if(x >= 'a' && x <= 'z')return true;
return false;
}
template<typename T>
void dispose(T *s){
T *a;
a = (T *)malloc(sizeof(s));
int i, j;
for(i = , j = ; s[i]; i++){
if(s[i] == ' ' || s[i] == '\t')continue;
a[j++] = is_lower(s[i]) ? s[i] : 'a' + s[i] - 'A';
// printf("%c %c\n", s[i], a[j - 1]);
}
a[j] = ;
strcpy(s, a);
}
template<typename T>
bool js(T *m, T *s){
int i, j;
for(i = , j = ; m[i] && s[i]; i++){
if(m[i] == s[j])j++;
}
if(s[j])return false;
return true;
}
int main(){
int T, kase = ;
scanf("%d", &T);
char mstr[], str[];
getchar();
while(T--){
gets(mstr);gets(str);
dispose(mstr);dispose(str);
sort(mstr, mstr + strlen(mstr));
sort(str, str + strlen(str));
if(js(mstr, str))
printf("Case %d: Yes\n", ++kase);
else
printf("Case %d: No\n", ++kase);
}
return ;
}
Time Limit: 2 second(s) | Memory Limit: 32 MB |
Rahaduzzaman Setu, (Roll - 12) of 13th batch, CSE, University of Dhaka. He passed away on 18th April 2012. This is one of the saddest news to all. May he rest in peace. This problem is dedicated to him.
This problem was written during his treatment. He will be in our prayers, always.
"He has been suffering from Multi Drug Resistant TB for a long time. Now, his left lung is damaged and beyond repair. No medicine is working on his body to ease his pain. It is urgent to operate on his left lung so that the disease doesn't spread to his right lung. It can either be removed through surgery or transplanted. He comes from a modest family and it is difficult and impossible for them to bare his medical expenses anymore. Because of the money needed (12 million BDT) to transplant, it is his family's decision to go with the surgery (3 million BDT). We must help them financially by raising money. But we must not be confined with that amount only to do the surgery. We must go for the Transplant. Our target will be to collect as much as possible to help our friend [link]."
However, in this problem, you have to build a software that can calculate the donations. Initially the total amount of money is 0 and in each time, two types of operations will be there.
1) "donate K" (100 ≤ K ≤ 105), then you have to add K to the account.
2) "report", report all the money currently in the account.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer N (1 ≤ N ≤ 100) denoting the number of operations. Then there will be N lines each containing two types of operations as given. You may assume that the input follows the restrictions above. Initially the account is empty for each case.
Output
For each case, print the case number in a single line. Then for each "report" operation, print the total amount of money in the account in a single line.
Sample Input |
Output for Sample Input |
2 4 donate 1000 report donate 500 report 2 donate 10000 report |
Case 1: 1000 1500 Case 2: 10000 |
题解:
让做一个软件,记录当前账户余额;
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
template<class T1, class T2>
class Software{
private:
T1 *s;
T2 money;
public:
Software();
void Check();
T2 Get();
void Put(T1 *s, T2 money);
~Software();
};
template<class T1, class T2>
Software<T1, T2>::Software():money(){}
template<class T1, class T2>
void Software<T1, T2>::Put(T1 *s, T2 money = ){
this->s = (T1 *)malloc(sizeof(s));
strcpy(this->s, s);
this->money += money;
}
template<class T1, class T2>
T2 Software<T1, T2>::Get(){
return money;
}
template<class T1, class T2>
void Software<T1, T2>::Check(){
if(strcmp(this->s, "report") == )
cout << Get() << endl;
}
template<class T1, class T2>
Software<T1, T2>::~Software(){
free(s);
}
int main(){
int T, N, kase = ;
cin >> T;
char s[];
long long money;
while(T--){
cin >> N;
printf("Case %d:\n", ++kase);
Software<char, int>a;
while(N--){
cin >> s;
if(s[] == 'd'){
cin >> money;
a.Put(s, money);
}
else{
a.Put(s);
}
a.Check();
}
}
return ;
}
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
You all probably know how to calculate the distance between two points in two dimensional cartesian plane. But in this problem you have to find the minimum arc distance between two points and they are on a circle centered at another point.
You will be given the co-ordinates of the points A and B and co-ordinate of the center O. You just have to calculate the minimum arc distance between A and B. In the picture, you have to calculate the length of arc ACB. You can assume that A and B will always be on the circle centered atO.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing six integers Ox, Oy, Ax, Ay, Bx, By where (Ox, Oy) indicates the co-ordinate of O, (Ax, Ay) denote the co-ordinate of A and (Bx, By) denote the co-ordinate of B. All the integers will lie in the range [1, 10000].
Output
For each case, print the case number and the minimum arc distance. Errors less than 10-3 will be ignored.
Sample Input
5
5711 3044 477 2186 3257 7746
3233 31 3336 1489 1775 134
453 4480 1137 6678 2395 5716
8757 2995 4807 8660 2294 5429
4439 4272 1366 8741 6820 9145
Sample Output
Case 1: 6641.81699183
Case 2: 2295.92880
Case 3: 1616.690325
Case 4: 4155.64159340
Case 5: 5732.01250253
题解:求弧长长度:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
template<typename T>
struct Point{
T x, y;
Point(T x = , T y = ):x(x),y(y){}
T getd(Point a, Point b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
};
template<typename T>
T getcos(T a, T b, T c){
return (b*b + c*c - a*a) / (*b*c);
}
int main(){
int N, kase = ;
scanf("%d", &N);
while(N--){
Point<double>o, a, b;
cin >> o.x >> o.y >> a.x >> a.y >> b.x >> b.y;
// cout << "r = " << o.getd(o, a) << " " << o.getd(o, b) << endl;
double r = o.getd(o, a), d = o.getd(a, b);
double coso = getcos(d, r, r);
double O = acos(coso);
double ans = O*r;
printf("Case %d: %lf\n", ++kase, ans);
}
return ;
}
Time Limit: 1 second(s) | Memory Limit: 32 MB |
A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:
Fig: a parallelogram
Now you are given the co ordinates of A, B and C, you have to find the coordinates of D and the area of the parallelogram. The orientation of ABCD should be same as in the picture.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case starts with a line containing six integers Ax, Ay, Bx, By, Cx, Cy where (Ax, Ay) denotes the coordinate of A,(Bx, By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range[-1000, 1000]. And you can assume that A, B and C will not be collinear.
Output
For each case, print the case number and three integers where the first two should be the coordinate of D and the third one should be the area of the parallelogram.
Sample Input |
Output for Sample Input |
3 0 0 10 0 10 10 0 0 10 0 10 -20 -12 -10 21 21 1 40 |
Case 1: 0 10 100 Case 2: 0 -20 200 Case 3: -32 9 1247 |
题解:找D,求面积。。。用java写了下,竟然wa。。。
代码:
package 随笔; import java.util.Scanner; class Point{
static Scanner cin = new Scanner(System.in);
public double x, y;
public Point(){
x = 0; y = 0;
}
public void Put(){
x = cin.nextDouble();
y = cin.nextDouble();
// System.out.println(x + " " + y);
}
public double Getd(Point a, Point b){
return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
public double Getarea(double r1, double r2, double r3){
// System.out.println(r1 + " " + r2 + " " + r3);
double r = (r1 + r2 + r3) / 2;
return Math.sqrt(r * (r - r1) * (r - r2) * (r - r3));
}
public Point GetD(Point a, Point b, Point c){
Point D = new Point();
D.x = a.x + c.x - b.x;
D.y = a.y + c.y - b.y;
return D;
}
} public class AreaofaParallelogram {
static Scanner cin = new Scanner(System.in);
public static void main(String[] args){
int kase = 0, N;
N = cin.nextInt();
while(N-- > 0){
Point a = new Point();
Point b = new Point();
Point c = new Point();
a.Put(); b.Put(); c.Put();
double r1, r2, r3, area;
r1 = a.Getd(a, b);
r2 = a.Getd(a, c);
r3 = a.Getd(b, c);
area = a.Getarea(r1, r2, r3) * 2;
Point D = new Point();
D = a.GetD(a, b, c);
//System.out.println("Case "+ (++kase) + ": " + " " + D.x + " " + D.y + " " + area);
System.out.printf("Case %d: %.0f %.0f %.0f", ++kase, D.x, D.y, area);
System.out.println();
}
}
}
2 seconds
256 megabytes
standard input
standard output
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 andaj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integersa1, a2, ..., an (|ai| ≤ 104) — the original array.
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
2 2 1
1
3 1 4 1
3
题解:+1 -1 也就是和能不能整除N能的话就是N,否则N- 1;
jsva写的:
import java.util.Scanner; public class Main {
static Scanner cin = new Scanner(System.in); public static void main(String[] args){
int N;
while(cin.hasNext()){
N = cin.nextInt();
int sum = ;
for(int i = ; i < N; i++){
sum += cin.nextInt();
}
if(sum % N == )
System.out.println(N);
else
System.out.println(N - );
}
}
}
LightOJ 1338 && 1387 - Setu && LightOJ 1433 && CodeForces 246B(水题)的更多相关文章
- Pearls in a Row CodeForces 620C 水题
题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意 给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对 ...
- 【Codeforces自我陶醉水题篇~】(差17C code....)
Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是 ...
- CodeForces 327B 水题。
I - 9 Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Codeforces - 631B 水题
注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...
- lightoj 1010 (水题,找规律)
lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...
- LightOJ 1166 Old Sorting 置换群 或 贪心 水题
LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : ...
- LightOJ 1065 - Number Sequence 矩阵快速幂水题
http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
随机推荐
- poj 3180 The Cow Prom(tarjan+缩点 easy)
Description The N ( <= N <= ,) cows are so excited: it's prom night! They are dressed in their ...
- 详述.NET里class和struct的异同
结构与类共享几乎所有相同的语法,但结构比类受到的限制更多:尽管结构的静态字段可以初始化,结构实例字段声明还是不能使用初始值设定项. 结构不能声明默认构造函数(没有参数的构造函数)或析构函数. 结构的副 ...
- Rotate It !!(思维)
Rotate It !! Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 【Spark Core】任务运行机制和Task源代码浅析1
引言 上一小节<TaskScheduler源代码与任务提交原理浅析2>介绍了Driver側将Stage进行划分.依据Executor闲置情况分发任务,终于通过DriverActor向exe ...
- Android应用程序资源管理器(Asset Manager)的创建过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8791064 在前面一篇文章中,我们分析了And ...
- Cisco cmd 命令(二)
1.配置路由器静态路由选择表 ip route [destination_network] [mask] [next_hop_address or exitinterface] [administra ...
- icon数目
[UIApplication sharedApplication].applicationIconBadgeNumber = currentBadgeValue.integerValue;
- css 梯形标签页
html 代码 略 css : nav > a{ position: relative; display: inline_block; padding: .3em 1em 0; } nav &g ...
- java一点东西(3)
运算符的优先级:()优先级最高 ! ++ -- 单目运算符 * / % + - > < <= >= == != && || 赋值符号 面向对象设计步骤:1.发现 ...
- CDZSC_2015寒假新人(1)——基础 h
Description Ignatius was born in a leap year, so he want to know when he could hold his birthday par ...