ACM: 浙江省赛题目 22:00 ~ 3:00 (…

Problem A: Taxi Fare

Time Limit: 2 Seconds         Memory Limit: 65536 KB

Last September, Hangzhou raised the taxi fares.

The original flag-down fare in Hangzhou was 10 yuan, plusing 2 yuan per kilometer after the first 3km and 3 yuan per kilometer after 10km. The waiting fee was 2 yuan per five minutes. Passengers need to pay extra 1 yuan as the fuel surcharge.

According to new prices, the flag-down fare is 11 yuan, while passengers pay 2.5 yuan per kilometer after the first 3 kilometers, and 3.75 yuan per kilometer after 10km. The waiting fee is 2.5 yuan per four minutes.

The actual fare is rounded to the nearest yuan, and halfway cases are rounded up. How much more money does it cost to take a taxi if the distance is d kilometers and the waiting time is t minutes.

Input

There are multiple test cases. The first line of input is an integer T ≈ 10000 indicating the number of test cases.

Each test case contains two integers 1 ≤ d ≤ 1000 and 0 ≤ t ≤ 300.

Output

For each test case, output the answer as an integer.

Sample Input
4
2 0
5 2
7 3
11 4
Sample Output
0
1
3
5

题意: 计算两种计程车计费方式的差值, 注意四舍五入

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int dist, mint;

int first()
{
 int d = dist;
 int time = mint;
 double sum = 0;
 if(d <= 3)
 {
  sum = 11;
 }
 else if(d > 3 && d <= 10)
 {
  sum = 11+(d-3)*2;
 }
 else
 {
  sum = 11+7*2+(d-10)*3;
 }
 sum += (time*0.4);
 if(sum > (int)sum)
 {
  double temp = sum-(int)sum;
  if(temp >= 0.5) sum = ((int)sum)+1;
  else sum = (int)sum;
 }
 return sum;
}

int second()
{
 int d = dist;
 int time = mint;
 double sum = 0;
 if(d <= 3)
 {
  sum = 11;
 }
 else if(d > 3 && d <= 10)
 {
  sum = 11+(d-3)*2.5;
 }
 else
 {
  sum = 11+7*2.5+(d-10)*3.75;
 }
 sum += (time*0.625);
 if(sum > (int)sum)
 {
  double temp = sum-(int)sum;
  if(temp >= 0.5) sum = ((int)sum)+1;
  else sum = (int)sum;
 }
 return sum;
}

int main()
{
// freopen("A.in","r",stdin);
 int caseNum;
 scanf("%d",&caseNum);
 while(caseNum--)
 {
  scanf("%d %d",&dist,&mint);
  int cost1 = first();
  int cost2 = second();
  printf("%d\n",cost2 - cost1);
 }
 return 0;

 

Problem D: Draw Something Cheat

Time Limit: 2 Seconds         Memory Limit: 65536 KB

Have you played Draw Something? It's currently one of the hottest social drawing games on Apple iOS and Android Devices! In this game, you and your friend play in turn. You need to pick a word and draw a picture for this word. Then your friend will be asked what the word is, given the picture you have drawn. The following figure illustrates a typical scenario in guessing the word.

word guessing in draw something

As you see, when guessing a word you will be given the picture and 12 letters. You must pick some of these letters to form a word that matches the picture. Each letter can only be used once. It is a lot of fun if your friend is a talented painter, but unfortunately some drawings from your friend are totally incomprehensible. After several times of becoming mad by the drawings, you find a way to cheat in the game.

In this game, letters not included in the correct answer are randomly generated. If you cannot find the correct answer when guessing, you can write down all the letters and restart the game. Then you would find some of these letters are changed. Of course these changed letters will never appear in the answer. By eliminating these letters you are a step closer to the answer.

So In this problem, you need to write a program to automate the cheating process. Given N strings of letters to the same picture, you need to eliminate as many letters as possible, and output the remaining letters.

Input

There are multiple test cases. The first line of the input is an integer T ≈ 1000 indicating the number of test cases.

Each test case begins with a positive integer N ≤ 20 indicating the number of times you have entered the game. Then N lines follow. Each line is a string of exactly 12 uppercase letters, indicating the candidate letters in one guess. It is guaranteed that the answer has at least 1 letter and has no more than 12 letters.

Output

For each test case, output the remaining letters in alphabet order after the process described above. One line for each test case.

Sample Input
2
2
ABCDEFGHIJKL
ABCDEFGHIJKL
2
SAWBCVUXDTPN
ZQTLFJYRCGAK
Sample Output
ABCDEFGHIJKL
ACT

题意: 要你写一个作弊程序, 因为每次出现的字符串是唯一的, 就可以每次统计出字符串中匹配的字符

      及其个数即可.

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 15

int n;
char str[MAX*MAX];
int a[27], b[27];

int main()
{
// freopen("D.in","r",stdin);
 int i, j;
 int caseNum;
 scanf("%d",&caseNum);
 while(caseNum--)
 {
  scanf("%d",&n);
  scanf("%s",str);
  int len = strlen(str);
  memset(a,0,sizeof(a));
  for(i = 0; i < len; ++i)
   a[ str[i]-'A' ]++;

  for(j = 1; j < n; ++j)
  {
   scanf("%s",str);
   len = strlen(str);
   memset(b,0,sizeof(b));
   for(i = 0; i < len; ++i)
    b[ str[i]-'A' ]++;

   for(i = 0; i < 26; ++i)
    a[i] = (a[i] > b[i] ? b[i] : a[i]);
  }

  for(i = 0; i < 26; ++i)
  {
   while(a[i]--)
    printf("%c",i+'A');
  }
  printf("\n");
 }
 return 0;

Problem F: Find the Marble

Time Limit: 2 Seconds         Memory Limit: 65536 KB

Alice and Bob are playing a game. This game is played with several identical pots and one marble. When the game starts, Alice puts the pots in one line and puts the marble in one of the pots. After that, Bob cannot see the inside of the pots. Then Alice makes a sequence of swappings and Bob guesses which pot the marble is in. In each of the swapping, Alice chooses two different pots and swaps their positions.

Unfortunately, Alice's actions are very fast, so Bob can only catch k of m swappings and regard these k swappings as all actions Alice has performed. Now given the initial pot the marble is in, and the sequence of swappings, you are asked to calculate which pot Bob most possibly guesses. You can assume that Bob missed any of the swappings with equal possibility.

Input

There are several test cases in the input file. The first line of the input file contains an integer N (N ≈ 100), then N cases follow.

The first line of each test case contains 4 integers n, m, k and s(0 < sn ≤ 50, 0 ≤ km ≤ 50), which are the number of pots, the number of swappings Alice makes, the number of swappings Bob catches and index of the initial pot the marble is in. Pots are indexed from 1 to n. Then m lines follow, each of which contains two integers ai and bi (1 ≤ ai, bin), telling the two pots Alice swaps in the i-th swapping.

Outout

For each test case, output the pot that Bob most possibly guesses. If there is a tie, output the smallest one.

Sample Input
3
3 1 1 1
1 2
3 1 0 1
1 2
3 3 2 2
2 3
3 2
1 2
Sample Output
2
1
3

题意: Alice和Bob玩游戏, Alice先将大理石放在n个pot中的一个编号为s, 然后交换m次, 但是Bob只可能看见

      m次交换中的k次. 问你每次游戏Bob最有可能在哪个编号的pot找到.

解题思路:

    1. 动态规划题: 状态dp[i][j][k]: 前i次交换, catch了j次, 出现在k-th pot上概率

    2. 状态转移方程: 每次交换的决策有2中, catch 和 没catch到. c[i][j]: i中选j个排列

       (1).dp[i+1][j][kk] += dp[i][j][kk] * c[m-i-1][k-j] / c[m-i][k-j]; //错过了当前这次交换

       (2).dp[i+1][j+1][t] += dp[i][j][kk] * c[m-i-1][k-j-1] / c[m-i][k-j]; //catch了当前这次交换

           t: //记录交换后catch到的编号

 

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 55

int n, m, k, s;
double c[MAX][MAX]; //不用double WA了两次
int a[MAX], b[MAX];
double dp[MAX][MAX][MAX]; //dp[i][j][k]:前i次交换, catch了j次, 出现在k-th pot上概率

void init()
{
 memset(c,0,sizeof(c));
 for(int i = 0; i < MAX-1; ++i)
 {
  c[i][0] = 1;
  if(i == 0) continue;
  for(int j = 1; j <= i; ++j)
   c[i][j] = c[i-1][j] + c[i-1][j-1];
 }
}

int main()
{
 init();
// freopen("F.in","r",stdin);
 int i, j, kk;
 int caseNum;
 scanf("%d",&caseNum);
 while(caseNum--)
 {
  scanf("%d %d %d %d",&n,&m,&k,&s);
  for(i = 1; i <= m; ++i)
   scanf("%d %d",&a[i],&b[i]);
  memset(dp,0,sizeof(dp));
  dp[0][0][s] = 1;

  for(i = 0; i < m; ++i)
  {
   for(j = 0; j <= i; ++j)
   {
    for(kk = 1; kk <= n; ++kk)
    {
     dp[i+1][j][kk] += dp[i][j][kk] * c[m-i-1][k-j] / c[m-i][k-j]; //错过了当前这次交换
     int t; //记录交换后catch到的下标
     if(a[i+1] == kk) t = b[i+1];
     else if(b[i+1] == kk) t = a[i+1];
     else t = kk;
     dp[i+1][j+1][t] += dp[i][j][kk] * c[m-i-1][k-j-1] / c[m-i][k-j]; //catch了当前这次交换
    }
   }
  }
  int result = 1;
  for(i = 2; i <= n; ++i)
  {
   if(dp[m][k][i] > dp[m][k][result])
    result = i;
  }
  printf("%d\n",result);
 }
 return 0;
}

 

Problem J: Modular Inverse

Time Limit: 2 Seconds         Memory Limit: 65536 KB

The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1x (mod m). This is equivalent to ax≡1 (mod m).

Input

There are multiple test cases. The first line of input is an integer T ≈ 2000 indicating the number of test cases.

Each test case contains two integers 0 < a ≤ 1000 and 0 < m ≤ 1000.

Output

For each test case, output the smallest positive x. If such x doesn't exist, output "Not Exist".

Sample Input
3
3 11
4 12
5 13
Sample Output
4
Not Exist
8

题意: 计算 ax = 1 (mod m) 中的最小x. 只需要注意当m == 1 && a == 1 时输出为 1即可

       扩展欧几里德水之

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

void ex_gcd(int a,int b,int &d,int &x,int &y)
{
 if(b == 0)
 {
  d = a;
  x = 1;
  y = 0;
 }
 else
 {
  ex_gcd(b,a%b,d,y,x);
  y -= x*(a/b);
 }
}

int a, m;

int main()
{
// freopen("J.in","r",stdin);
 int caseNum;
 scanf("%d",&caseNum);
 while(caseNum--)
 {
  scanf("%d %d",&a,&m);
  int x, y;
  int b, c, d;
  b = m;
  c = (m+1)%m;

  ex_gcd(a,b,d,x,y);
  if(m == 1)
   printf("1\n");
  else if(c % d != 0)
   printf("Not Exist\n");
  else
  {
   while(x < 0) x += b;
   printf("%d\n",(x % (b/d) + (b/d)) % (b/d));
  }
 }
 return 0;
}

 

Problem K: Yet Another Story of Rock-paper-scissors

Time Limit: 2 Seconds         Memory Limit: 65536 KB

Akihisa and Hideyoshi were lovers. They were sentenced to death by the FFF Inquisition. Ryou, the leader of the FFF Inquisition, promised that the winner of Rock-paper-scissors would be immune from the punishment. Being lovers, Akihisa and Hideyoshi decided to die together with their fists clenched, which indicated rocks in the game. However, at the last moment, Akihisa chose paper and Hideyoshi chose scissors. As a result, Akihisa was punished by the FFF Inquisition and Hideyoshi survived alone.

When a boy named b and a girl named g are being punished by the FFF Inquisition, they will play Rock-paper-scissors and the winner will survive. If there is a tie, then neither of they will survive. At first, they promise to choose the same gesture x. But actually, the boy wants to win and the girl wants to lose. Of course, neither of them knows that the other one may change his/her gesture. At last, who will survive?

Input

There are multiple test cases. The first line of input is an integer T ≈ 1000 indicating the number of test cases.

Each test case contains three strings -- b g x. All strings consist of letters and their lengths never exceed 20. The gesture x is always one of "rock", "paper" and "scissors".

Output

If there is a tie, output "Nobody will survive". Otherwise, output "y will survive" where y is the name of the winner.

Sample Input
1
Akihisa Hideyoshi rock
Sample Output
Hideyoshi will survive

题意: 这题主要看懂题意太水了, 极其简单博弈题. boy 和 girl 玩石头剪纸布一开始约好出一样的.

      但是boy一心想胜利, girl一心想输掉, 因为大家一样的时候, 大家就会都输. (女孩心地好吧.呵呵)

      所以每次都是girl胜利

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 105

char str1[MAX], str2[MAX], str3[MAX];

int main()
{
// freopen("K.in","r",stdin);
 int caseNum;
 scanf("%d",&caseNum);
 while(caseNum--)
 {
  scanf("%s %s %s",str1,str2,str3);
  printf("%s will survive\n",str2);
 }
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值