acm 防超时 防大数据手动输入 小技巧

本文介绍如何通过文件输入避免debug时重复输入,并利用clock_t测量程序运行时间以优化性能,同时提供禁用cin/cout与stdio同步的方法。

1.debug时防止多次重复输入,要从文件读取输入信息,只需要在main下加入一行

freopen("input.txt","r",stdin);       

即可从创建的项目文件夹里读取文件信息到程序中,所以只需要事先把样例赋值了放在程序目录下即可

同理,要输出到文件,这样写即可

    freopen("output.txt", "w", stdout);  

2.超时,这里需要引入<ctime>(c中为<time.h>)头文件

然后重点来了,代码如下

#include <iostream>
#include <ctime>
using namespace std;

const int INF = 0x3f3f3f3f;
const int maxn = 1e7+5;
typedef long long ll;

int main() {
    int n,m;
    clock_t start,finish;
    start =clock();
    for(int i=0;i<INF;i++);
    finish = clock();
    cout << 1.0*(finish - start)/CLOCKS_PER_SEC<<endl;    
    return 0;
    }

定义开始时间和结束时间,分别在程序开头和结尾获取当前时间,然后相减即为滴答次数(程序每运算一次滴答次数+1,相当于钟摆),然后除以
CLOCKS_PER_SEC,这是time头文件的一个宏定义,代表一秒钟能够进行滴答的次数,用总次数除以单位时间,就为程序总耗时
含有输入的话可以结合1读取文件或者在输入结束后再获取start 的时间点.
3.输入输出挂
禁用cin cout与stdin,stdio的同步,可以将cin cout 提高到和scanf printf差不多的效率
ios::sync_with_stdio(false); 


I Boxes(c++题解,代码禁止有注释,本题测试数据极大,极易超时,极易0分,极易内存超限,极易段错误与编译错误!) 作者 北京大学 单位 北京大学 Given n points in three-dimensional space, the task is to partition them into some mutually disjoint subsets S 1 ​ ,S 2 ​ ,…,S k ​ . For any i  =j, the partition must satisfy at least one of the following three conditions: volume(conv(S i ​ )∩conv(S j ​ ))=0, conv(S i ​ )⊆conv(S j ​ ), conv(S j ​ )⊆conv(S i ​ ). Here, the convex hull conv(S i ​ ) of a subset S i ​ is defined as: conv(S i ​ )={∑ p∈S i ​ ​ λ p ​ p∣λ p ​ ≥0,∑ p∈S i ​ ​ λ p ​ =1}. The goal is to maximize 6∑ i=1 k ​ volume(conv(S i ​ )). The challenge is to find the optimal partition that achieves the maximum total volume of the convex hulls while ensuring these constraints are met. Input: There are multiple test cases in a single test file. The first line of the input contains a single integer T (1≤T≤3000), indicating the number of test cases. For each test case, the first line of the input contains one integer n (4≤n≤3000) --- the number of points. The following n lines each contain three integers x i ​ , y i ​ , and z i ​ (0≤x i ​ ,y i ​ ,z i ​ ≤10 6 ), representing the coordinates of point p i ​ in three-dimensional space. It's guaranteed that no four points are coplanar, and the sum of n over all test cases does not exceed 3000. Output: For each test case, output a single integer --- the maximum sum of volumes of the convex hulls under the given conditions, multiplied by 6. It can be proven that this value is always an integer. Sample Input: 2 4 0 0 1 0 0 2 0 1 1 1 1 1 10 2 6 3 2 9 0 2 1 0 3 7 3 0 5 6 10 9 2 4 4 2 8 5 2 4 6 9 6 7 5 Sampe Output: 1 943 代码长度限制 16 KB Java (javac) 时间限制 3000 ms 内存限制 1024 MB Python (python3) 时间限制 3000 ms 内存限制 1024 MB Python (pypy3) 时间限制 3000 ms 内存限制 1024 MB 其他编译器 时间限制 1000 ms 内存限制 1024 MB 栈限制 131072 KB
最新发布
12-09
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值