个人赛
Rudolf has registered for a programming competition that will follow the rules of ICPC. The rules imply that for each solved problem, a participant gets
In total,
A powerful artificial intelligence has predicted the values
Rudolf realized that the order of solving problems will affect the final result. For example, if
Rudolf became interested in what place he will take in the competition if each participant solves problems in the optimal order based on the predictions of the artificial intelligence. It will be assumed that in case of a tie in points and penalty, Rudolf will take the best place.
The first line contains an integer
Then follow the descriptions of the test cases.
The first line of each test case contains three integers
Then there are
The sum of
For each test case, output an integer — Rudolf's place in the final table if all participants solve problems in the optimal order.
非常简单的题目,模拟ACM赛制计算排名。但是坑点写的时候有几个没注意到的。
罚时。罚时的计算上和正式赛是一样的,计算时间的时候是从头到尾的计算,所以需要维护前缀和
做题数。做题数到
至于为什么不是
同分同罚时排序。
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef struct node
{
int sumnum;int pentally;int no;
bool operator<(const node &x)const
{
return (x.sumnum>sumnum)||(x.sumnum==sumnum&&x.pentally<pentally)||(x.sumnum==sumnum&&x.pentally==pentally&&x.no<no);
}
}node;
void solve()
{
int n,m,h;
cin>>n>>m>>h;
vector<int>peo(m+1);
priority_queue<node>q;
for(int i=0;i<n;i++)
{
peo.clear();
for(int j=0;j<m;j++)
{
int a;
cin>>a;
peo.push_back(a);
}
sort(peo.begin(),peo.end());
int timer=0;
int sumss=0;
int j=0;
while(j<m&&sumss+peo[j]<=h)
{
sumss+=peo[j];
timer+=sumss;
j++;
}
q.push({j,timer,i+1});
}
int ans=1;
while(!q.empty()&&q.top().no!=1)
{
ans++;
q.pop();
}
cout<<ans<<endl;
return;
}
signed main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
system("pause");
return 0;
}
Rudolph drew a beautiful Christmas tree and decided to print the picture. However, the ink in the cartridge often runs out at the most inconvenient moment. Therefore, Rudolph wants to calculate in advance how much green ink he will need.
The tree is a vertical trunk with identical triangular branches at different heights. The thickness of the trunk is negligible.
Each branch is an isosceles triangle with base
The figure below shows an example of a tree with
Help Rudolph calculate the total area of the tree branches.
The first line contains a single integer
Then follow the descriptions of the test cases.
The first line of each test case contains three integers
The second line of each test case contains
The sum of
For each test case, output a single real number on a separate line — the total area of the tree branches. The answer will be considered correct if its absolute or relative error does not exceed
非常简单的计算,使我的大脑旋转。
应用相似三角形计算重叠部分面积(我当时写的时候是直接累算不重叠部分,效果一样)
问题在于算高度差上界的时候取小了,赛后翻查
还有就是误差不超过
#include<bits/stdc++.h>
using namespace std;
#define double long double
double y[200009];
const double INF=9982443530;
void solve()
{
int n;
double d,h;
cin>>n>>d>>h;
double S=0.5*d*h;
double ans=0;
for(int i=1;i<=n;i++)
{
cin>>y[i];
}
y[n+1]=INF;
for(int i=2;i<=n+1;i++)
{
double dely=y[i]-y[i-1];
if(dely>h)dely=h;
ans+=(1-1.0*(1.0*(h-dely)*(h-dely)/(1.0*h)/(1.0*h)))*S;
}
cout<<fixed<<setprecision(7)<<ans<<endl;
return;
}
signed main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
system("pause");
return 0;
}
询问
This is the hard version of the problem. The only difference is that in this version
One winter morning, Rudolf was looking thoughtfully out the window, watching the falling snowflakes. He quickly noticed a certain symmetry in the configuration of the snowflakes. And like a true mathematician, Rudolf came up with a mathematical model of a snowflake.
He defined a snowflake as an undirected graph constructed according to the following rules:
The smallest possible snowflake for
After some mathematical research, Rudolf realized that such snowflakes may not have any number of vertices. Help Rudolf check whether a snowflake with
The first line of the input contains an integer
Then follow the descriptions of the test cases.
The first line of each test case contains an integer
Output
题面翻译已经非常明确了。
这是困难版本,原题数据太水了,暴力都能直接过。
困难版本下,数据范围大幅增大,极限状态下(
怎么处理?
注意到,如果是
对于非突袭关,直接暴力存
注意,需要用等比数列公式,要不然加法太多超时。而且,因为有分出不通过
对于突袭模式剩下的数据范围,因为只可能
显然求根公式更快,不是吗?
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
map<int,int>mp;
__int128 now;
void init()
{
int cnt=0;
for(int i=2;i<=(1e6-1);i++)
{
now=i*i;
for(int q=2;;q++)
{
now*=i;
if((now-1)/(i-1)>1e18)break;
else mp[(now-1)/(i-1)]=1;
}
}
}
void solve()
{
int n;
cin>>n;
if(n<=6)
{
cout<<"NO"<<endl;
return;
}
if(mp[n])cout<<"YES"<<endl;
else
{
int ans=(-1+sqrt(4*n-3))/2;
if(ans*ans+ans+1!=n)
cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return;
}
signed main()
{
init();
int t;
cin>>t;
while(t--)
{
solve();
}
system("pause");
return 0;
}
本题有
对于每组测试数据,给定整数
要求重新排列
保证一定有解。
对于
You are given an array
You are also given an array
Determine which day was which temperature, if you know that the weather never differs from the forecast by more than
For example, let an array
The first line of input data contains a single integer
The description of the test cases follows.
The first line of each test case contains two integers
The second line of each test case contains exactly
The third line of each test case contains exactly
It is guaranteed that the sum of
On a separate line for each test case, output exactly
If there is more than one answer — output any of them.
这个题目多少是挺抽象的一个题目。首先可以想到暴力枚举每一种情况肯定是超时间的,涉及到n个元素的全排列,时间长度成本过大。
观察数据范围,基本肯定本题可以在线性的时间复杂度或者最多支持
想到极端情况下,
(赛场上根据题目总体难度推断直接就交了一发,没想到还真蒙过去了)
现在严谨的证明该做法的正确性。
继续上面的思路,那如果
涵盖了所有预测天气的值,那么此时不管什么顺序都是正解,可行解域包含排序后数组。
对于其他情况,易证,只要存在两个真实天气的浮动范围没有交集,那么这两天的真实天气一定服从大小次序分布。对于相交部分,会视情况可交换(相互覆盖)、不可交换(单侧覆盖)。
故,有序序列一定是可行解,且一定是最优的可行解。
如果存在某一种可能的真实天气,对于预测天气而言,单调不降序列无解而存在一个逆序数为1的解的话,反证明其不可能存在。
如果二者浮动范围无交集,显然不可能。假设分别为
如果二者浮动范围有交集并且相邻。
此时满足条件的$b_i$和$b_j$交换后仍然满足浮动条件,与假设矛盾。
使用贪心的构造想法。
如果想让两个序列的对应标准差之和最小,那么两个序列一定都是按同种排序顺序从小到大或者从大到小排序的
在
那么此时虽然各项标准差不一定都是最优的,但是他们一定都是小于等于
因为存在各相差都小于等于
证明结束,顺序一定是一个解。
(好像有点问题?)
程序就不放了,没啥意思。只是理论思维挺好玩的。
请我喝杯咖啡吧~