• Educational Codeforces Round 7、


    A - Infinite Sequence

    题意:有一种这样的无限序列数 1,1,2,1,2,3.....   (如果最大数n,那么就有从1到n的所有1到n的数);

    思路:题意只给了1秒、直接模拟肯定超时,我用的是二分找下界

     1 #include<iostream>
     2 using namespace std;
     3 long long f(long long x)
     4 {
     5     return (1+x)*x/2;
     6 }
     7 long long search(long long x)
     8 {
     9     int l,r,m;
    10     l=0;r=1e8;
    11     while(l<=r){
    12         m=(l+r)/2;
    13         if(f(m)>=x)    r=m-1;
    14         else        l=m+1; 
    15     }
    16     return l;
    17 }
    18 int main()
    19 {
    20     long long n;
    21     while(cin >> n){
    22         long long ans;
    23         ans=search(n);
    24         ans=n-f(ans-1);
    25         cout << ans << endl;
    26     }
    27 }
     1 #include<stdio.h>
     2 int main()
     3 {
     4     long long int n,i,k;
     5     scanf("%lld",&n);
     6     i=1;
     7     k=n;
     8     while(k>i)
     9     {
    10         k-=i;
    11         i++;
    12     }
    13     printf("%lld",k);
    14     return 0;
    15 }

    B - The Time   

    题意:给一个时间给你,然后给你个分钟时间给你,让你相加

    思路:直接模拟算

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 int main()
     5 {
     6     int a,b;
     7     while(~scanf("%d%*c%d%*c",&a,&b)){
     8         int c;scanf("%d",&c);
     9         int ans=c/60;
    10         int cns=c%60;
    11         ans+=(cns+b)/60;
    12         ans+=a;
    13         cns=(cns+b)%60;
    14         ans=ans%24;
    15         printf("%02d:%02d
    ",ans,cns);
    16     }
    17 }
  • 相关阅读:
    Some day some time we will do
    qemu-img 的使用
    虚拟化qemu-img的简单用法。
    linux 后台执行命令
    C#向服务器上传文件问题
    Canvas保存为图片
    一个Sql备注
    fabric Clone
    Js 正则获取Html元素
    Graphic 完成文字缩放
  • 原文地址:https://www.cnblogs.com/sasuke-/p/5186258.html
Copyright © 2020-2023  润新知