6 条题解

  • 0
    @ 2026-7-6 1:39:12

    我们可以直接调用系统函数获知输入文件大小,减去 22 得到答案,将时间复杂度降至 O(1)O(1)!

    #include <stdio.h>
    #include <fcntl.h>
    #include <sys/stat.h>
    #include <unistd.h>
    int main()
    {
    	struct stat st;
    	fstat(open("log.in", O_RDONLY), &st);
    	freopen("log.out", "w", stdout);
    	printf("%ld\n", st.st_size - 2);
    	return 0;
    }
    
    • @ 2026-10-7 20:52:37

      但是我们需要输出 O(log⁡log⁡n)O(\log \log n) 个字符,所以是 O(log⁡log⁡n)O(\log \log n) 的(???)

  • 0
    @ 2026-3-29 16:44:01

    水篇题解。

    AC Code:

    #include <bits/stdc++.h>
    using namespace std;
    
    string s;
    
    int main() {
        freopen("log.in", "r", stdin);
        freopen("log.out", "w", stdout);
        cin >> s;
        s.erase(s.end() - 1);
        cout << s.size();
        return 0;
    }
    
    • 0
      @ 2025-10-22 23:36:14

      由于增加了换行符,所以只需要在读入字符串后删去最后一个字符即可。

      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          freopen("log.in","r",stdin);
          freopen("log.out","w",stdout);
          string s;
          cin>>s;
          s.erase(s.end()-1);
          cout<<s.size();
      }
      

      是运行时间最多的……

      • 0
        @ 2025-9-5 20:39:40

        已知,⌊lg⁡n⌋\lfloor\lg n\rfloor 所得到的结果就是 nn 的位数减 11。

        由于数据量过大,我们只能采用字符串输入的形式,而不能使用 long long。

        代码如下:

        // P2. [System Test] Common Logarithm
        // code by:cirrationaler
        // time:2025/08/21
        #include <bits/stdc++.h>
        
        using namespace std;
        
        string s;
        
        int main()
        {
            // freopen("code.in", "r", stdin);
            freopen("log.in", "r", stdin);
            freopen("log.out", "w", stdout);
            cin >> s;
            s.erase(s.end() - 1);
            cout << s.size();
            return 0;
        }
        
        
        • 0
          @ 2025-9-5 18:31:41
          $$\left \lfloor \lg\ n\right \rfloor = \text{len}(n)-1$$
          #include<bits/stdc++.h>
          using namespace std;
          int main(){
              freopen("log.in","r",stdin);// 文件读取
              freopen("log.out","w",stdout);// 文件写入
              char a=getchar();// 获取一个字符
              int ans=-1;// 之所以 ans 初始值为 -1,是因为答案是 len(n) - 1
              while(a!='\n'){// 若 a 为 \n 就不是数字了
                  ans++;// 因为 a 还是数字所以加上 1
                  a=getchar();// 获取一个字符
              }
              cout<<ans<<endl;// 输出
              fclose(stdin);// fclose 好习惯
              fclose(stdout);// fclose 好习惯
              return 0;// return 好习惯
          }
          
          • 0
            @ 2025-9-4 21:59:14

            众所周知,⌊lg⁡n⌋=d−1\lfloor\lg n\rfloor=d-1,其中 dd 是 nn 的数字位数。

            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
            	freopen("log.in", "r", stdin);
            	freopen("log.out", "w", stdout);
            	int cnt = 0;
            	char c = getchar();
            	while(c != '\n')
            	{
            		cnt++;
            		c = getchar();
            	}
            	printf("%d\n", cnt - 1);
            	return 0;
            }
            
            • 1

            信息

            ID
            2
            时间
            1000ms
            内存
            512MiB
            难度
            2
            标签
            递交数
            118
            已通过
            25
            上传者