题目链接:http://codeforces.com/contest/592/problem/B
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2, 3, ..., n (in this particular order). And then she puts a walnut in each region inside the polygon.
Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.
Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
The first and only line of the input contains a single integer n (3 ≤ n ≤ 54321) - the number of vertices of the regular polygon drawn by Ari.
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
5
9
3
1
One of the possible solutions for the first sample is shown on the picture above.
找规律。
#include<bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; cout<<(n-2)*(n-2)<<endl; }
─────────────────────────────────────────────────────────────────────────────────────────────
题目链接:http://codeforces.com/contest/592/problem/C
#include<bits/stdc++.h> using namespace std; typedef unsigned long long llu; inline llu gcd(llu m,llu n){return n?gcd(n,m%n):m;} llu lcm(llu m,llu n){return m/gcd(m,n)*n;} void output(llu p,llu q) { llu pq_gcd=gcd(p,q); cout<<p/pq_gcd<<"/"<<q/pq_gcd<<endl; } bool check(llu t,llu w,llu b) { return log(w*1.0)+log(b*1.0)-log(gcd(w,b)*1.0)>log(t*1.0); } int main() { llu t,w,b; cin>>t>>w>>b; llu tail=min(w,b)-1;//tail>=0 if(check(t,w,b))//判断lcm(w,b)>t? { output(min(tail,t),t); return 0; } llu wb_lcm=lcm(w,b); llu cnt=t/wb_lcm; if(cnt==0) { if(t<=tail) { cout<<"1/1"<<endl; return 0; } else { output(tail,t); return 0; } } else if(cnt==1) { llu ed=min(t%wb_lcm,tail)+1; output(tail+ed,t); return 0; } else { llu ed=min(t%wb_lcm,tail)+1; output(tail+(cnt-1)*(tail+1)+ed,t); return 0; } }