B - B

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:

  1. You can change some uppercase letters to lower case and vice versa.
  2. You can add/remove spaces freely.
  3. 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 ;
}
1387 - Setu
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 ;
}
E - E

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 ;
}
Area of a Parallelogram
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();
}
}
}
Increase and Decrease
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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 aiaj (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.

Input

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.

Output

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

Examples
input
2 2 1
output
1
input
3 1 4 1
output
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(水题)的更多相关文章

  1. Pearls in a Row CodeForces 620C 水题

    题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意 给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对 ...

  2. 【Codeforces自我陶醉水题篇~】(差17C code....)

    Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是 ...

  3. CodeForces 327B 水题。

    I - 9 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  4. Codeforces - 631B 水题

    注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...

  5. lightoj 1010 (水题,找规律)

    lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...

  6. LightOJ 1166 Old Sorting 置换群 或 贪心 水题

    LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : ...

  7. LightOJ 1065 - Number Sequence 矩阵快速幂水题

    http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - ...

  8. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  9. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

随机推荐

  1. Top 15 Tools To Make Animated GIFs From Images & Video

    Creating an animated GIF picture from photos or video with Adobe Photoshop is easy, but not everyone ...

  2. jQuery Pagination Ajax分页插件中文详解(摘)

    jQuery Pagination Ajax分页插件中文详解 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxin ...

  3. Java之Static静态修饰符详解

    Java之Static静态修饰符详解 Java之Static静态修饰符详解 一.特点 1.随着类的加载而加载,随着类的消失而消失,生命周期最长 2.优先于对象存在 3.被所有类的对象共享 4.可以直接 ...

  4. Hook linux 网络封包

    要注册一个hook函数需要用到nf_register_hook()或者nf_register_hooks()系统API和一个struct nf_hook_ops{}类型的结构体对象 一个简单的demo ...

  5. Linux 内核开发 - 进程空间

    1.1 虚拟内存 Linux 的系统.假设每一个任务都独立的占用内存,则实际的物理内存将非常快消耗殆尽.实际上对于前台正在执行的任务来说,所须要要的内存并不多,非常多任务基本不须要执行,也就没有必要一 ...

  6. BOOST 线程完全攻略 - 扩展 - 事务线程

    扩展threadtimermoduleexceptionsocket 什么叫事务线程 举个例子: 我们写一个IM客户端的登录子线程,则该子线程会有这么几个事务要处理 No.1 TCP Socket物理 ...

  7. 【MySql】Linux下更改转移mysql数据库目录

    1.关闭MySql: #service mysqld stop 2.转移数据: #cd /var/lib   #ls   #cp -a mysql /opt/mysql/ 3.修改配置文件,一下三个: ...

  8. Android-----输入法的显示和隐藏

    /** * 控制手机虚拟键盘的显示和隐藏 */public class InputMethodUtil { /** * 隐藏虚拟键盘 * @param v  参数v为获取焦点对象view */ pub ...

  9. SQL日期形式转换

    在SQL Server中,有时存储在数据库中的日期格式和我们需要显示在页面上的格式不相同,我们需要转化成需要的格式. 特在此总结了一下常用的日期格式. --当前时间 SELECT GETDATE(); ...

  10. Autorelease Pool-自动释放池

    Autorelease Pool是Objective-C中的内存管理方式之一,它与线程和NSAutorelease类有关.每一个线程都拥有自己的Autorelease Pool栈,这个栈底层是由双向链 ...