湖南大学ACM程序设计新生杯大赛

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述


Two endpoints of two line segments on a plane are given to determine whether the two segments are intersected (there is a common point or there is a partial coincidence that intersects). If intersected, output "Yes", otherwise output "No".

输入描述:

The first line is a number of T, indicating the number of tests inputed (1 <= T <= 1000)
For next T line,each line contains 8 numbers , x1,y1,x2,y2,x3,y3,x4, y4. (8-10 ^ < = xi, yi < = 10 ^ 8)
(the two endpoints of line 1 are x1, y1, |, x2, y2, and two of the endpoints of line 2 are x3, y3, |, x4, y4).

输出描述:

For each test case, output"Yes"  if the two segments intersected, else output"No".
示例1

输入

2
1 2 2 1 0 0 2 2
-1 1 1 1 0 0 1 -1

输出

Yes
No
      
      
解出两条线所在的直线方程,联立,求交点,判断交点范围
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
     int T; cin >> T;
     while (T--)
     {
         double x1, y1, x2, y2, x3, y3, x4, y4;
         cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
         double k1 = (y1 - y2) / (x1 - x2);
         double k2 = (y3 - y4) / (x3 - x4);
         double x = (k1*x1 - k2*x3 - y1 + y3) / (k1 - k2);
         if (x1 > x2) swap(x1, x2);
         if (x3 > x4) swap(x3, x4);
         if (x >= x1&&x <= x2&&x >= x3&&x <= x4) cout <<  "Yes" << endl;
         else cout <<  "No" << endl;
     }
     return 0;
}
      
      
时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 65536K,其他语言131072K 64bit IO Format: %lld

题目描述

We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), and prime fourth power(四次方).
The first four Shuaishuai numbers are:
How many Shuaishuai numbers in [1,n]? (1<=n<=50 000 000)

输入描述:

The input will consist of a integer n.

输出描述:

You should output how many Shuaishuai numbers in [1...n]
示例1

输入

28

输出

1

说明

There is only one Shuaishuai number
50000000开根号小于7200;7200以内的素数一千左右的样子,而50000000开四次方小于九十,90以内的素数不足20个;时间复杂度可以接受
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
bool b[7202];
using namespace std;
map< int int > P;
int main()
{
     memset (b, 1,  sizeof (b));
     for ( long long i = 2; i <= 7200; i++)
     {
         if (b[i] == 1)
         {
             for ( long long j = i + i; j <= 7200; j = j + i)
             {
                 b[j] = 0; //标记素数
             }
         }
     }
     long long a[1500];  long long l = 0;
     for ( long long i = 2; i <= 7200; i++)
         if (b[i] == 1) a[++l] = i;    // a[i]存储素数   
     long long n;
     while ( scanf ( "%lld" , &n) != EOF)
     {
         long long s = 0;
         for ( long long i = 1; i <= l; i++)
         {
             for ( long long j = 1; j <= l; j++)
             {
                 for ( long long k = 1; k <= l; k++)
                 {
                     long long y = a[i] * a[i] + a[j] * a[j] * a[j] + a[k] * a[k] * a[k] * a[k];
                     if (y > n)  break ;
                     int tt = ( int )y;
                     if (P[tt] == 1)  continue ; //三个不同的数的平方立方四次方和可能相同,若相同,continue;开始没想到这点,卡了好多次;
                     P[tt] = 1;  //若此前无此值,s++;
                     s++;
                 }
             }
         }
         printf ( "%lld\n" , s);
     }
     return 0;


      
      
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld

题目描述

A mod-dot product between two arrays with length n produce a new array with length n. If array A is a1,a2,...,an and array B is b1,b2,...bn, then A mod-dot B produce an array C c1,c2,...,cn such that c1 =  a1*b1%n, c2 = a2*b2%n,...,ci = ai*bi%n,..., cn = an*bn%n.
i.e. A = [2,3,4] and B = [5,2,2] then A mod-dot B = [1,0,2].
A permutation of n is an array with length n and every number from 0 to n-1 appears in the array by exactly one time.
i.e. A = [2,0,1] is a permutation of 3, and B = [3,4,1,2,0] is a permutation of 5, but C = [1,2,2,3] is NOT a permutation of 4.
Now comes the problem: Are there two permutaion of n such that their mod-dot product is also a permutation of n?

输入描述:

The only line with the number n (1 <= n <= 1000)

输出描述:

If there are such two permutation of n that their mod-dot product is also a permutation of n, print "Yes" (without the quote). Otherwise print "No" (without the quote).
示例1

输入

2

输出

Yes

说明

A = [0,1] and B = [0,1]. Then A mod-dot B = [0,1]
示例2

输入

997

输出

No

备注:

1 <= n <= 1000

      
      
看似复杂的简单题,n大于2时不可能有情况成立
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
     int n;cin>>n;
     if (n<3)
         cout<< "Yes" ;
     else
         cout<< "No" ;
     cout<<endl;
     return 0;
}
      
      
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld

题目描述

BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called 'socks heap'.By maintaining this structure, he can quickly pick out two of the most smelless socks from millions of socks everyday. As one of his good friends, you know the data structure of BSD, and want to predict 'the air pollution level' of a certain day. Of course, it's BSD's socks that pollute the air.

We will enter numbers that indices for 'socks smell level' and expect you to output the total amount of pollution that he will wear on the day of BSD design.

输入描述:

First line contain an integer T 1<T<=10 ,means the sum of test cases.
for every test cases,we will firstly give N(1<N<1000000) in a single line,means the count of socks.Next line Contains N numbers (you can use int to save all of them) ,means 'smell level' for every socks.

输出描述:

please putout answer in a single line for every test cases.
示例1

输入

3
5
1 1 2 3 5
3
1 4 7
3
200 4 10000

输出

2
5
204
            
            
找出两个最小值输出和即可
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
     int T; cin >> T;
     while (T--)
     {
         int n; cin >> n;
         int m1 = 999999999, m2 = 999999999;
         for ( int i = 1; i <= n; i++)
         {
             int a; cin >> a;
             if (a < m1) m2 = m1, m1 = a;
             else if (a >= m1&&a < m2) m2 = a;
         }
         cout << m1 + m2 << endl;
     }
     return 0;
}

            
            
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld

题目描述

Yuanyuan Long is a dragon like this picture?

                                   
I don’t know, maybe you can ask him. But I’m sure Yuanyuan Long likes ballons, he has a lot of ballons.          

One day, he gets n white ballons and k kinds of pigment, and he thought a problem:

1.      Number these ballons b1, b2,  … , bi, …,  to bn.

2.      Link these ballons to a circle in order, and color these ballons.

3.      He need to make sure that any neighbor ballons have different colors.

He wants to know how many solutions to solve this problem. Can you get the answer to him? The answer maybe very large, get the answer MOD 100000007.

For Example: with 3 ballons and 3 kinds of pigment

Your answer is 3*2*1 MOD 100000007 = 6. 
The answer maybe large, you can use integer type long long.

输入描述:

The first line is the cases T. ( T <=
100)
For next T lines, each line contains n and
k. (2<= n <= 10000,  2<= k
<=100)

输出描述:

For each test case, output the answer on
each line.
示例1

输入

3
3 3
4 2
5 3

输出

6
2
30
假定b1为一种颜色,推出bn的可能方案数,和bn与b1颜色相同的情况数bn2; 输出bn-bn2即可
                  
                  
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<cmath>
long long t = 100000007;
using namespace std;
long long quick( long long a,  long long b)
{
     long long h = 1;
     while (b)
     {
         if (b % 2 == 1)
             h = h*a%t;
         a = a*a%t;
         b = b / 2;
     }
     return h%t;
}
int main()
{
     int T; cin >> T;
     while (T--)
     {
         long long n, k; cin >> n >> k;
         long long s = 0;
         if (n % 2 == 0)
         {
             long long h = 0;
             for ( int i = 2; i <= n - 2; i = i + 2)
             {
                 h = (h + quick(k - 1, i)) % t;
             }
             s = k*((k - 1) + h*(k - 2)) % t;
             cout << s << endl;
         }
         else
         {
             long long h = 0;
             for ( int i = 1; i <= n - 2; i = i + 2)
             {
                 h = (h + quick(k - 1, i)) % t;
             }
             s = k*(k - 2)*h%t;
             cout << s << endl;
         }
     }
     return 0;
}
                  
                  
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld

题目描述

Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and it is inadvertently caught in the peach blossom trap.

Fortunately, it has got a map of peach blossom trap. You can think of it as a matrix of R row and C column. ‘.’ stand for the road you can walk. ‘*’ means there is a peach tree planted in this grid, and obviously you can’t go into it.

The pig can only walk up to four adjacent squares in the upper, lower, left and right directions at a time. The outside of the matrix is the paradise of freedom, and of course, it may never go out.

Though it has got the map, but doesn't know where it is in the peach blossom trap now, that means it could be at any ‘.’ in the matrix. It finds you smart to tell it the probability it can get out of peach blossom trap, please tell him the answer in the form of p/q. 

输入描述:

Multiple groups of test case. (no more than 100 groups. )
The first line of each group contains two numbers R and C,(0<=R, C<=1000), representing the number of rows and the number of columns of peach blossom trap, respectively. Stop the program when R and C are both 0.
Then there are next R lines, each line contains C characters, either '.' or '*'.
It is guarantee at least one grid is'. '.

输出描述:

For each test case, output the answer in the form of p/q on each line. Notice that p/q must be the fraction in lowest terms.
示例1

输入

5 5
*..*.
**.**
*.*.*
*...*
*****
3 3
***
*.*
***
0 0

输出

4/9
0/1

说明

In the first sample, the number of grids the pig may appear is 9 , of which there are 4 grids it can escape from the trap, so the answer is 4/9.
搜索迷宫的四条边,若‘.'在边界上,则与他相连的'.'都是可行解
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<queue>
char a[1002][1002];
int d[4][2] = { {-1,0},{1,0},{0,-1},{0,1} },s,n,m;
using namespace std;
void bfs( int x,  int y)
{
     queue< int > P; P.push(x), P.push(y);
     a[x][y] =  '*' ;
     while (!P.empty())
     {
         int x11 = P.front(); P.pop();
         int y11 = P.front(); P.pop();
         for ( int i = 0; i < 4; i++)
         {
             int xx = x11 + d[i][0], yy = y11 + d[i][1];
             if (xx < 0 || xx >= n || yy < 0 || yy >= m)  continue ;
             if (a[xx][yy] ==  '.' )
             {
                 a[xx][yy] =  '*' ;
                 s++;
                 P.push(xx), P.push(yy);
             }
         }
     }
}
int zz( int x,  int y)
{
     if (x > y) swap(x, y);
     int r = 1;
     while (r)
     {
         r = x%y;
         x = y;
         y = r;
     }
     return x;
}
int main()
{
     while ( scanf ( "%d%d" , &n, &m) != EOF)
     {
         if (n == 0 && m == 0) break ;
         s = 0;
         for ( int i = 0; i < n; i++)
             cin >> a[i];
         int t = 0;
         for ( int i = 0; i < n; i++)
             for ( int j = 0; j < m; j++)
                 if (a[i][j] ==  '.' )
                     t++;
         for ( int i = 0; i < m; i++)
         {
             if (a[0][i] ==  '.' )
                 s++,bfs(0, i);
             if (a[n - 1][i] ==  '.' )
                 s++, bfs(n - 1, i);
         }
         for ( int i = 0; i < n; i++)
         {
             if (a[i][0] ==  '.' )
                 s++, bfs(i, 0);
             if (a[i][m - 1] ==  '.' )
                 s++, bfs(i, m - 1);
         }
         int p = zz(s, t);
         printf ( "%d/%d\n" , s / p, t / p);
     }
     return 0;
}

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e18) guys standing in a row, because the boys had some strange character,The first time to Liao them will not be successful, but the second time will be successful; third times to Liao them  will not be successful, but the fourth time will be successful;....... By analogy (toxic psycho)
So the little koala burst odd thought of a fancy up method. The N is the sum of handsome boys, and labeled from 1 to N, starting from the first guy, whose number is 1, she will Liao all the boys whose number is Multiple of 1, then number 2 and all the boys whose number is Multiple of 2(toxic method)
Later, little Kola found that some handsome guys did not get her Liao, she asked the smart you to help her look for how many handsome guys did not successfully be Liaoed?


输入描述:
Multiple groups of Case. (no more than 10000 groups)
Each group of data is 1 lines, with an integer N per line.
The N is 0 at the end of the input.
输出描述:
Each group of Output1 rows, a number of 1 lines representing the number of boys with no Liao to the group of data.
示例1
输入


1
2
3
4
0
输出


1
1
1
2
自己手写了几行找出了规律,即如果此人的number开根号结果为整数,则此人不能被撩,因此sum=n-(int)sqrt(n);
但是这样由于精度问题样例通过率为99.98%,因此需做一下优化
      
      
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
 
double eps = 1e-10;
 
int main()
{
     long long n;
     while ( scanf ( "%lld" ,&n)!=EOF)
     {
         if (n==0)  break ;
         long long t = ( long long )( sqrt (1.0 * n));
         while ((t + 1) * (t + 1) <= n) t ++;
         while (t * t > n) t --;
         printf ( "%lld\n" ,t);
     }
     return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值