Timus 1981. Parallel and Perpendicular
1981. Parallel and Perpendicular
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
You are given a regular n-gon. Your task is to calculate two values: the number of its diagonals that are parallel to at least one of its other diagonals, and the number of its diagonals that
are perpendicular to at least one of its diagonals. A diagonal is a segment connecting two non-adjacent polygon vertices.
Input
The only line contains an integer n (4 ≤ n ≤ 105).
Output
Output two required numbers.
Sample
input | output |
---|---|
4 |
0 2 |
Problem Author: Grigory Nazarov
Tags: none
)這是當時比賽的思路,可以A掉。
這是少討論了6啊。TAT!!!
程式碼:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
long long n;
while(~scanf("%lld",&n))
{
long long a,b;
if(n==4) cout<<"0 2"<<endl;
else if(n==5) cout<<"0 0"<<endl;
else if(n==6) cout<<"6 9"<<endl; //有三根是不存在平行,只有垂直的
else
{
if(!(n&1))
{
a=(n/2)*((n-2)/2); //與點平行的
a+=(n/2)*((n-4)/2); //與邊平行的
b=a;
}
else
{
a=n*(n-3)/2;
b=0;
}
printf("%lld %lld\n",a,b);
}
}
return 0;
}
後來仔細想了下,原來兩種情況原來是一樣的,偶數的時候奇數的時候都是求得所有的對角線,當時怎麼就沒發現,確實是這樣,每條對角線都會有平行的,如果是偶數,每條對角線有垂直的。當時沒有多想。。
AC程式碼:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
long long n;
while(~scanf("%lld",&n))
{
long long a,b;
if(n==4) cout<<"0 2"<<endl;
else if(n==5) cout<<"0 0"<<endl;
else if(n==6) cout<<"6 9"<<endl; //有三根是不存在平行,只有垂直的
else
{
a=n*(n-3)/2; //所有對角線的條數
b=0;
if(!(n&1)) b=a;
printf("%lld %lld\n",a,b);
}
}
return 0;
}
當時察覺出來了6有點奇怪,因為中間的對角線沒有平行的,短路了。。
相關文章
- oracle hint_no_parallel_no_parallel_indexOracleParallelIndex
- oracle hint_parallel_parallel_indexOracleParallelIndex
- Tasks in parallelParallel
- Parallel DMLParallel
- about datapump parallelParallel
- 並行(Parallel)並行Parallel
- Oracle Parallel ParametersOracleParallel
- Oracle's ParallelOracleParallel
- Oracle Parallel ExecutionOracleParallel
- Parallel query & viewsParallelView
- Oracle Parallel DMLOracleParallel
- oracle parallel並行_引數parameter_parallel_max_serverOracleParallel並行Server
- PARALLEL_DEGREE_POLICParallel
- parallel_max_serversParallelServer
- Parallel操作測試Parallel
- Parallel Execution of SQL StatementsParallelSQL
- oracle Parallel技術OracleParallel
- db file parallel writeParallel
- 關於Parallel queryParallel
- Oracle db file parallel write 和 log file parallel write 等待事件 說明OracleParallel事件
- 使用parallel注意事項Parallel
- parallel_index不生效ParallelIndex
- Understanding Parallel Execution PlanParallel
- SMON: Parallel transaction recovery triedParallel
- Parallel Query Wait EventsParallelAI
- Parallel 並行技術Parallel並行
- expdp = exp + direct mode + parallel ?Parallel
- EXPDP的parallel引數Parallel
- oracle expdp中的parallelOracleParallel
- Parallel Access to External Tables (173)Parallel
- parallel rollback引數總結Parallel
- 聊聊flink的Parallel ExecutionParallel
- DataPump Export/Import Of LOBs Are Not Executed in ParallelExportImportParallel
- Export with Spool and Parallel Utl_FileExportParallel
- oracle hint_noappend_parallelOracleAPPParallel
- Dictionary inconsistency caused by CTAS in PARALLELParallel
- control file parallel writeParallel
- direct-path [insert] parallelParallel