BNU34067——Pair——————【找规律】

Pair

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format:  %lld      Java class name: Main
Type: 
None
 
  None   Graph Theory       2-SAT       Articulation/Bridge/Biconnected Component       Cycles/Topological Sorting/Strongly Connected Component       Shortest Path           Bellman Ford           Dijkstra/Floyd Warshall       Euler Trail/Circuit       Heavy-Light Decomposition       Minimum Spanning Tree       Stable Marriage Problem       Trees       Directed Minimum Spanning Tree       Flow/Matching           Graph Matching               Bipartite Matching               Hopcroft–Karp Bipartite Matching               Weighted Bipartite Matching/Hungarian Algorithm           Flow               Max Flow/Min Cut               Min Cost Max Flow   DFS-like       Backtracking with Pruning/Branch and Bound       Basic Recursion       IDA* Search       Parsing/Grammar       Breadth First Search/Depth First Search       Advanced Search Techniques           Binary Search/Bisection           Ternary Search   Geometry       Basic Geometry       Computational Geometry       Convex Hull       Pick's Theorem   Game Theory       Green Hackenbush/Colon Principle/Fusion Principle       Nim       Sprague-Grundy Number   Matrix       Gaussian Elimination       Matrix Exponentiation   Data Structures       Basic Data Structures       Binary Indexed Tree       Binary Search Tree       Hashing       Orthogonal Range Search       Range Minimum Query/Lowest Common Ancestor       Segment Tree/Interval Tree       Trie Tree       Sorting       Disjoint Set   String       Aho Corasick       Knuth-Morris-Pratt       Suffix Array/Suffix Tree   Math       Basic Math       Big Integer Arithmetic       Number Theory           Chinese Remainder Theorem           Extended Euclid           Inclusion/Exclusion           Modular Arithmetic       Combinatorics           Group Theory/Burnside's lemma           Counting       Probability/Expected Value   Others       Tricky       Hardest       Unusual       Brute Force       Implementation       Constructive Algorithms       Two Pointer       Bitmask       Beginner       Discrete Logarithm/Shank's Baby-step Giant-step Algorithm       Greedy       Divide and Conquer   Dynamic Programming                   Tag it!

 给出一个正整数N,从1到N这N个数中选出若干对pair,每个pair是1到N中不相等的两个数,1到N中每个数只能被选择一次,每个pair的值是它两个数的和,要求任意两个pair的值不相等,并且每个pair的值不超过N,问最多可以选出多少个pair。

 

Input

第一行为一个整数T,代表数据组数,T<=100。

接下来T行,每行一个正整数N,N<=100。

 

Output

对于每个输入N,输出最多可以选出多少对pair,每个输出占一行。

 

Sample Input

3
1
2
3

Sample Output

0
0
1

Hint

样例解释:

N=1时,不能选出两个数,所以为0;

N=2时,只能选出1和2组成一个pair,但是1+2=3>2,所以也为0;

N=3时,可以选择1和2组成一个pair,1+2=3<=3,可行,并且答案最大为1。

 

Source

 
 
解题思路:五个一循环。0 0 1 1 1。2 2 3 3 3 。4 4 5 5 5 。6 6 7 7 7 。
 
 
#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int N;
        scanf("%d",&N);
        int n=N/5;
        int m=N%5;
        if(m==0){
            printf("%d\n",n*2-1);
        }else {
            n*=2;
            if(m>2)
                printf("%d\n",n+1);
            else{
                printf("%d\n",n);
            }
        }
    }
    return 0;
}

  

 
 

转载于:https://www.cnblogs.com/chengsheng/p/4409884.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值