文章

211

粉丝

1

获赞

1176

访问

55.6k

头像
防水堤坝 题解:
P1669 中南大学机试题
发布于2026年2月6日 14:29
阅读数 504

#include<bits/stdc++.h>
using namespace std;

int main() {
	long long K;
    while (cin >> K) {
        double ans;
        long long m = K / 2;      
        if (K % 4 == 0) {
            // K = 4, 8, 12...
            ans = (double)m * m / 2.0;
        } else if (K % 4 == 1) {
            // K = 5, 9, 13...
            ans = (double)m * (m + 1) / 2.0 - 0.5;
        } else if (K % 4 == 2) {
            // K = 6, 10, 14...
            ans = (double)(m * m - 1) / 2.0;
        } else {
            // K % 4 == 3, 即 K = 3, 7, 11...
            if (K == 3) ans = 0.5;
            else ans = (double)m * (m + 1) / 2.0 - 0.5;
        }       
        cout << fixed << setprecision(1) << ans << endl;
    }  
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发