Tju 3497 3495 (集训第一场练习赛)

/*
3497.   The job of Mike's mother
--------------------------------------------------------------------------------
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 194   Accepted Runs: 55

--------------------------------------------------------------------------------

 

Mike's mother has a new job recently. The working time of this job has 2 normal kinds and 1 special. 3 days is a circle. The first day has two period of working: 7:00 ~ 11:00, 18:30 ~ 23:00. The working time of the second day is 16:00 ~ 23:00. Then she will have a whole day to rest. When she meets a special day which is Thuesday and she has to work from 16:00 till 23:00, she must change the start of the working time. It begins at 11:30 till 23:00.

Now Mike nees help to figure out when his mother is working. 27 Feb 2010, Sat. Resting

Input
It may has n cases(0 < n <= 10000). One case One line. Every case is the date of the day. These dates are all after the 2010/2/27, and before the year 2200.

Output
Depend the dates of the Input, the program must output the working time of that day.

Sample Input
2010/2/27
2010/2/28
2010/3/16
2010/3/1
Sample Output
Resting
7:00-11:00, 18:30-23:00
11:30-23:00
16:00-23:00

*/
#include <iostream>//When she meets a special day which is Thuesday(Tuesday) and she has to work from 16:00 till 23:00,
    // she must change the start of the working time. It begins at 11:30 till 23:00.
#include <cstdio>//就因为这句话没有看清楚,一直错了,群里发消息但是没有去看悲剧的
using namespace std;

int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
 if(y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
  return true;
 else
  return false;
}
int sum_day(int y, int m, int d)
{
 int sum = 0;
 if(y == 2010)
 {
  //if(m == )
  for(int i = 2; i < m; i++)
  sum += day[i];
  sum += d - 27;
 }
 else
 {
  for(int i = 2; i <= 12; i++)
   sum += day[i];
   sum -= 27;
  for(int i = 2011; i < y; i++)
   if(leap(i))
    sum += 366;
   else
    sum += 365;
  for(int i = 1; i < m; i++)
  {
   sum += day[i];
  }
  if(leap(y) && m > 2)
   sum += 1;
  sum += d;
 }
 return sum;
}
int main()
{
 int y, m ,d;
 char a, b;
 while(cin >> y >> a >> m >> b >> d)
 {
  int sum = sum_day(y, m, d);
  if(sum % 3 == 1)
  {
    printf("7:00-11:00, 18:30-23:00/n");
  }
  else if(sum % 3 == 2)
  {
   if(sum % 7 == 3 && sum % 3 == 2)
    printf("11:30-23:00/n");
   else
    printf("16:00-23:00/n");
  }
  else
  {
    printf("Resting/n");
   
  }


 }
}

 

 

/*
3495.   A Simple Game
--------------------------------------------------------------------------------
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 330   Accepted Runs: 70

--------------------------------------------------------------------------------

 

Alice and Bob are playing a simple game . They have N integer number and a target number T in common . Either of them independently and randomly picks a number from the N numbers . They win the game if the product of the two picked numbers is strictly greater than the target number T .

You are to calculate the probability that they will win . Assume that each numble is picked with the same probability.

Input
The input consists of multiple test cases . Each test case consists of two lines . The first line contains two integers N (1 ≤ N ≤ 30,000) and T (-1,000,000,000 ≤ T ≤ 1,000,000,000) . The second line contains N integers numbers that Alice and Bob have , each of which will be between -30,000 and 30,000 , inclusive . The last test case is followed by a line containing two zeros.

Output
For each test case , print a line containing the test case number ( beginning with 1 ) followed by the probability of which Alice and Bob will win the game . The probability is printed as a fraction number formatted as “a/b”, where the greatest common divisor of a and b must be 1.

Sample Input
2 0
2 -9
4 5
1 -4 3 -2
0 0
Sample Output
Case 1: 1/2
Case 2: 1/4

*/
#include <iostream>//以下是xwc的AC的代码
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
#define INF 0x7fffffff
int a[30030];

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

int main()
{
 int n, m;
 int i, j;
 int test = 1;
 int num;
 
 while (scanf("%d %d", &n, &m) != EOF)
 {
  if (n == 0 && m == 0)
  {
   break;
  }
  for (i = 1; i <= n; i++)
  {
   scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
 
  int low = 1;
  int high = n;
  int slave_id = -1;
  while (low <= high)
  {
   int mid = (low + high) / 2;
   if (a[mid] >= 0)
   {
    high = mid - 1;
    slave_id = mid;
   } 
   else
   {
    low = mid + 1;
   }
  }
  if ((slave_id == -1 && m < 0) || (slave_id == 1 && m < 0))
  {
   printf("Case %d: 0/n", test++);
   continue;
  }
  else
  {
   int tmpa = a[1] * a[1];
   int tmpb = a[n] * a[n];
   int mmax = tmpa;
   if (mmax < tmpb)
   {
    mmax = tmpb;
   }
   if (mmax <= m)
   {
    printf("Case %d: 0/n", test++);
    continue;
   }
   
   if (m < 0)//只要这里换一下就wrong
   {
    
    num = (slave_id - 1) * (slave_id - 1);
    num += (n - slave_id + 1) * (n - slave_id + 1);
    for (i = slave_id - 1; i >= 1; i--)
    {
     if (a[i] * a[slave_id] <= m)
     {
      break;
     }
     for (j = slave_id; j <= n; j++)
     {
      if (a[i] * a[j] > m)
      {
       num += 2;
      }
      else
      {
       break;
      }
     }
    }
   }
   else
   {
    num = 0;
    for (i = 1; i < slave_id; i++)
    {
     if (a[i] * a[i] > m)
     {
      num++;
     }
     else
     {
      break;
     }
     for (j = i + 1; j < slave_id; j++)
     {
      if (a[i] * a[j] > m)
      {
       num += 2;
      }
      else
      {
       break;
      }
     }
    }
    
    for (i = n; i >= slave_id; i--)
    {
     if (a[i] * a[i] > m)
     {
      num++;
     }
     else
     {
      break;
     }
     for (j = i - 1; j >= slave_id; j--)
     {
      if (a[i] * a[j] > m)
      {
       num += 2;
      }
      else
      {
       break;
      }
     }
    }
   }
  }
  //puts("---");
  if (num == 0)
  {
   printf("Case %d: 0/n", test++);
   continue;
  }
  int sum = n * n;
  int p = gcd(num, sum);
  num /= p;
  sum /= p;
  printf("Case %d: %d/%d/n", test++, num, sum);
 }
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值