莫名其妙被唐老師的帶進了這個專題。。。。
A題:
You are building a house. You'd prefer if all the walls have a precise right angle relative to the ground, but you have no device to measure angles. A friend says he has a great idea how you could ensure that all walls are upright: All you need to do is step away a few feet from the wall, measure how far away you are from the wall, measure the height of the wall, and the distance from the upper edge of the wall to where you stand. You friend tells you to do these measurements for all walls, then he'll tell you how to proceed. Sadly, just as you are done, a timber falls on your friend, and an ambulance brings him to the hospital. This is too bad, because now you have to figure out what to do with your measurements yourself.
Given the three sides of a triangle, determine if the triangle is a right triangle, i.e. if one of the triangle's angles is 90 degrees.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each test case consists of three integers 1 ≤ a, b, c ≤ 40000 separated by a space. The three integers are the lengths of the sides of a triangle.
Output
For each case, print the case number and "yes" or "no" depending on whether it's a right angle or not.
Sample Input
2
36 77 85
40 55 69
Sample Output
Case 1: yes
Case 2: no
就是說輸入三條邊判斷一個三角形是不是直角三角形,直接給邊排順序,然後找到勾股關係就行了。
代碼:
# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>
using namespace std;
# define inf 999999999
int main(void)
{
int t;cin>>t;
int icase = 1;
while ( t-- )
{
int a,b,c;
cin>>a>>b>>c;
int sum = a+b+c;
int a1 = max(c,max(a,b));
int c1 = min(c,min(a,b));
int b1 = sum-a1-c1;
printf("Case %d: ",icase++);
if ( a1*a1==c1*c1+b1*b1 )
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}
B題:
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if there exists an integer c such that a = b * c.
Input
Input starts with an integer T (≤ 525), denoting the number of test cases.
Each case starts with a line containing two integers a (-10200 ≤ a ≤ 10200) and b (|b| > 0, b fits into a 32 bit signed integer). Numbers will not contain leading zeroes.
Output
For each case, print the case number first. Then print 'divisible' if a is divisible by b. Otherwise print 'not divisible'.
Sample Input
6
101 101
0 67
-101 101
7678123668327637674887634 101
11010000000000000000 256
-202202202202000202202202 -101
Sample Output
Case 1: divisible
Case 2: divisible
Case 3: divisible
Case 4: not divisible
Case 5: divisible
Case 6: divisible
一個簡單的大數除法,只要明確分清楚負數和正數的除法就可以了。
代碼:
# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>
using namespace std;
typedef long long LL;
# define inf 999999999
int main(void)
{
int t;cin>>t;
int icase = 1;
string s;
getchar();
while ( t-- )
{
LL b;
LL cur = 0;
cin>>s>>b;
if ( s[0]!='-' )
{
for ( int i = 0;i < s.size();i++ )
{
cur = cur*10+s[i]-'0';
cur = cur%b;
}
}
else
{
for ( int i = 1;i < s.size();i++ )
{
cur = cur*10+s[i]-'0';
cur = cur%b;
}
}
printf("Case %d: ",icase++);
if ( cur==0 )
{
printf("divisible\n");
}
else
{
printf("not divisible\n");
}
s.clear();
}
return 0;
}
C題:
解題思路:
其實就是求每個串的逆序數,然後按照從小到大進行排序就OK了。注意在struct中使用string的妙處。。
代碼:
# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>
using namespace std;
typedef long long LL;
# define inf 999999999
# define MAX 100+4
struct node
{
string dna;
int cnt;
}a[MAX];
int cmp ( const struct node & x,const struct node & y )
{
return x.cnt < y.cnt;
}
int main(void)
{
int n,m;
while ( cin>>n>>m )
{
for ( int i = 0;i < m;i++ )
{
cin>>a[i].dna;
a[i].cnt = 0;
for ( int j = 0;j < n-1;j++ )
{
for ( int k = j+1;k < n;k++ )
{
if ( a[i].dna[j] > a[i].dna[k] )
{
a[i].cnt++;
}
}
}
}
stable_sort(a,a+m,cmp);
for ( int i = 0;i < m;i++ )
{
cout<<a[i].dna<<endl;
}
}
return 0;
}
D題:
Description
Sometimes I feel angry to arrange contests, because I am too lazy. Today I am arranging a contest for AIUB students. So, I made a plan. While they will be busy with the contest, as a punishment I will cover their rooms with dusts. So, when they will be back, they will surely get angry, and it will cause them some pain.
So, at first, I will make up my mind, that means I will fix the amount of dusts for each student. This amount may not be same for all. Now you are given the amount of dust unit for each student. You have to help me finding the total dust unit I have to collect to cause them pain.
But there is a problem, my random function which generates dust units for students has a bug, it sometimes returns negative numbers. If a student gets negative number, I think he is lucky, so I will not cause him any pain with dusts.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a blank line. The next line contains an integer N (1 ≤ N ≤ 1000), means that there are N students. The next line will contain Nintegers separated by spaces which denote the dust unit for all students. The dust unit for any student will not contain more than two digits.
Output
For each case print the case number and the total required dust units.
Sample Input
2
3
1 5 10
2
1 99
Sample Output
Case 1: 16
Case 2: 100
解題思路:求n個數字的和,如果a[i]<0,那麼a[i]==0..
代碼:
# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>
using namespace std;
typedef long long LL;
# define inf 999999999
# define MAX 1000+4
int a[MAX];
int main(void)
{
int t;cin>>t;
int icase = 1;
while ( t-- )
{
int n;cin>>n;
int sum = 0;
for ( int i = 0;i < n;i++ )
{
cin>>a[i];
if ( a[i] < 0 )
a[i]=0;
sum+=a[i];
}
printf("Case %d: ",icase++);
cout<<sum<<endl;
}
return 0;
}
E題:
解題思路:大數加法,用數組給寫掛了,等我學了JAVA的大數在更新~
代碼:
F題:
解題思路:一個簡單的DFS,只要搜索出來@開始的'.'的個數就可以了。
代碼:
# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>
using namespace std;
# define inf 999999999
# define MAX 23
int ans;
int w,h;
char grid[MAX][MAX];
int book[MAX][MAX];
int next[4][2]={ {1,0},{0,-1},{-1,0},{0,1} };
void dfs( int x,int y )
{
grid[x][y] = '#';
for ( int i = 0;i < 4;i++ )
{
int now_x = x+next[i][0];
int now_y = y+next[i][1];
if ( now_x >=1&&now_x <= h&&now_y >= 1&&now_y <= w )
{
if ( grid[now_x][now_y]=='.' )
{
ans++;
dfs(now_x,now_y);
}
}
}
return;
}
int main(void)
{
int t;cin>>t;
int icase = 1;
while ( t-- )
{
cin>>w>>h;
for ( int i = 1;i <= h;i++ )
{
for ( int j = 1;j <= w;j++ )
{
cin>>grid[i][j];
}
}
int st_x;
int st_y;
for ( int i = 1;i <= h;i++ )
{
for ( int j = 1;j <= w;j++ )
{
if ( grid[i][j] == '@' )
{
st_x = i;
st_y = j;
}
}
}
ans = 1;
dfs( st_x,st_y );
printf("Case %d: %d\n",icase++,ans);
}
return 0;
}
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z