题目链接:Codeforces 392A Blocked Points
题目大意:给出一个n,然后距离原点距离小于n的都为积分点,其他都为非积分点,现在要求阻塞尽量少得积分点,使得没有一个积分点可以连接到非积分点。
解题思路:暴力o(n),枚举一个象限的边界情况再乘4,跑了1s。现场的时候TLE了,原因是多加了一个floor函数进行类型转换,完全多此一举。还有注意一个坑点就是n为0的时候。
#include#include #include #include #include using namespace std; typedef long long ll; int main () { ll n, ans = 0; cin >> n; double R = n; ll tmp = n, k; for (ll i = 1; i <= n; i++) { double r = i; k = (ll)sqrt(R*R - r*r); ans += (tmp == k ? 1 : tmp - k); tmp = k; } if (n == 0) cout << 1 << endl; else cout << ans * 4 << endl; return 0; }