zoukankan      html  css  js  c++  java
  • 双基contest

    Problem Description

    有两个球在长度为L的直线跑道上运动,两端为墙。0时刻小球a以1m/s的速度从起点向终点运动,t时刻小球b以相同的速度从终点向起点运动。问T时刻两球的距离。这里小球与小球、小球与墙的碰撞均为弹性碰撞,所有过程没有能量损失。

    Input

    先输入一个q,代表q组数据,然后每组3个整数 L,t,T。
    1<=L<=1000;0<=t<=1000;t<=T<=1000;

    Output

    一个整数,代表答案。

    Sample Input

    2
    10 4 7
    8 3 9

    Sample Output

    0
    5
    两个球,动态模拟
    #include<bits/stdc++.h>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    typedef long long ll;
    #define INF 0x3f3f3f3f
    const int mod=1e9+7;
    
    ll q_pow(ll n,ll m){
        ll  ans=1;
        while(m){
            if(m&1) ans=ans*n%mod;
            m>>=1;
            n=n*n%mod;
        }
        return ans;
    }
    //快速排序
    int  quick_sort(int s[], int l, int r){
        if (l < r){
            //Swap(s[l], s[(l + r) / 2]); //将中间的这个数和第一个数交换 参见注1
            int i = l, j = r, x = s[l];
            while (i < j){
                while(i < j && s[j] >= x) // 从右向左找第一个小于x的数
                    j--;
                if(i < j){
                    s[i++] = s[j];
                }
                while(i < j && s[i] < x) // 从左向右找第一个大于等于x的数
                    i++;
                if(i < j){
                    s[j--] = s[i];
            }
            s[i] = x;
    
            quick_sort(s, l, i - 1); // 递归调用
            quick_sort(s, i + 1, r);
        }
      }
    }
    int main(){
        ios::sync_with_stdio(0);
        int te;
        cin>>te;
        int L,t,T,add,sub;
        int Di,De;
        while(t--){
            cin>>L>>t>>T;
            Di=0,De=L;
            add=1,sub=-1;
            for(int i=1;i<=T;i++){
                if(i>t){Di+=add,De+=sub;}
                    else{Di+=add; }
                    if(Di==De){add=-1,sub=1;}
                    if(Di==0){add=1;}
                    if(Di==L){add=-1; }
                    if(De==0){sub=1;}
                    if(De==L){sub=-1;}
            }
            cout<<abs(De-Di)<<endl;
        }
        return 0;
    }

    QAQ

    Problem Description

    定义操作:将数 n 变为 f(n) = floor(sqrt(n))。即对一个数开平方后,再向下取整。
    如对 2 进行一次操作,开平方再向下取整, 1.414213562..... = 1 , 即变为了 1 。
    现在给出一个数 n,如果能在 5 次操作内把 n 变为 1,则输出操作次数;如果则超过5次输出"QAQ"。
    数据范围:
    1<= n <= 10^100

    Input

    多组输入,每行输入一个数 n。

    Output

    每组数据输出要多少次操作,或者输出"QAQ"

    Sample Input

    233
    233333333333333333333333333333333333333333333333333333333

    Sample Output

    3
    QAQ
    

     stringstream stream

     1 #include<cstdio>
     2 #include <bits/stdc++.h>
     3 #include <algorithm>
     4 #include<cstring>
     5 #include <string>
     6 #include<iostream>
     7 #include<sstream>
     8 #include <cstdlib>
     9 using namespace std;
    10 
    11 int main(){
    12   string s1;
    13     int n;
    14     ios::sync_with_stdio(0);
    15     while(cin >> s1){
    16       n = s1.length();
    17       if(n > 12) {
    18           cout << "QAQ"<<endl;
    19       }else {
    20         long long m=0;
    21       std::stringstream stream;
    22         stream<<s1;
    23         stream>>m;
    24         bool flag=0;
    25         int ans=0;
    26         while(m!=1){
    27         m = sqrt(m);
    28         ans++;
    29       }
    30          if(ans<=5) cout<<ans<<endl;
    31        else cout<<"QAQ"<<endl;
    32     }
    33     }
    34               return 0;
    35 }


  • 相关阅读:
    Peer code review
    分析图书管理系统的5W1H
    项目风险分析作业
    课堂练习
    功能分析四个象限
    Android需求分析作业
    电梯演说模板练习
    敏捷流程的理解
    团队模型的小组辩论
    结对编程任意Demo
  • 原文地址:https://www.cnblogs.com/z-712/p/7899062.html
Copyright © 2011-2022 走看看