【数学规律】A、 Frog Jumping

数学规律题: 题目链接

思路:分情况讨论,①跳奇数次s=(n-1)/2*(a-b)+a②跳偶数次s=(n)/2*(a-b)

注意:结果可能很大,用lld或者BigInteger解决

import java.math.BigInteger;
import java.util.Scanner;
import java.util.*;
import java.lang.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner cin=new Scanner(System.in);
    int n=cin.nextInt();
    while(n--!=0)
    {
      int a=cin.nextInt(),b=cin.nextInt(),dis=a-b;
      BigInteger c=cin.nextBigInteger();
      if((c.mod(BigInteger.valueOf(2))).equals(BigInteger.ZERO))
      {
        c=c.divide(BigInteger.valueOf(2));
        System.out.println(c.multiply(BigInteger.valueOf(dis)));
      }
      
      else {
        c=c.subtract(BigInteger.ONE);
        c=c.divide(BigInteger.valueOf(2));
        c=c.multiply(BigInteger.valueOf(dis));
        System.out.println(c.add(BigInteger.valueOf(a)));
      }
      
    
    }
  
  }	
}

 

Codeforces:Oh Those Palindromes

A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, “abcba“, “a“, and “abba” are palindromes, while “abab” and “xy” are not.

A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, “abc“, “ab“, and “c” are substrings of the string “abc“, while “ac” and “d” are not. 继续阅读Codeforces:Oh Those Palindromes