gym 101873
题还没补完
以下是牢骚:删了
现在只有六个。。。太恐怖了,我发现四星场我连300人的题都不会啊。
C:最短路加一维状态就好了叭。。嗯,一开始没看到输出的那句话 那个 "."也要输出,然后n,m看反了,这反人类啊这nm。
- #include <bits/stdc++.h>
- #define mk(a,b) make_pair(a,b)
- #define pii pair<int,int>
- using namespace std;
- typedef long long ll;
- struct node{
- int u,t,p;
- bool operator<(const node&rhs)const {
- return p>rhs.p;
- }
- };
- int x,n,m,l;
- vector<int>g[];
- int t[],p[],dis[][];
- void Dijkstra(){
- for(int i=;i<=n;i++)for(int j=;j<=x;j++)dis[i][j]=;
- if(t[]>x)return;
- dis[][t[]]=p[];
- priority_queue<node>Q;
- Q.push(node{,t[],p[]});
- while (!Q.empty()){
- node fr = Q.top();Q.pop();
- if(dis[fr.u][fr.t]<fr.p)continue;
- if(fr.t+t[fr.u]<=x&&fr.p+p[fr.u]<dis[fr.u][fr.t+t[fr.u]]){
- dis[fr.u][fr.t+t[fr.u]]=fr.p+p[fr.u];
- Q.push(node{fr.u,fr.t+t[fr.u],fr.p+p[fr.u]});
- }
- for(auto u:g[fr.u]){
- if(fr.t+t[u]+l<=x&&fr.p+p[u]<dis[u][fr.t+t[u]+l]) {
- dis[u][fr.t+t[u]+l]=fr.p+p[u];
- Q.push(node{u, fr.t + t[u] + l, fr.p + p[u]});
- }
- }
- }
- }
- int main(){
- ios::sync_with_stdio(false);
- cin>>x>>n>>m>>l;
- int a,b;
- for(int i=;i<=m;i++){
- cin>>a>>b;
- g[a].push_back(b);
- g[b].push_back(a);
- }
- for(int i=;i<=n;i++){
- cin>>t[i]>>p[i];
- }
- Dijkstra();
- if(dis[][x]==)cout<<"It is a trap."<<endl;
- else cout<<dis[][x]<<endl;
- }
D:签到,我写的很傻逼
- #include <bits/stdc++.h>
- #define mk(a,b) make_pair(a,b)
- #define pii pair<int,int>
- using namespace std;
- typedef long long ll;
- string s1,s2,s;
- int n,m,cnt=,vis[];
- map<string,int>mp;
- vector<int>g[];
- set<int> st[];
- void dfs(int v){
- st[v].insert(v);
- for(auto u:g[v]){
- dfs(u);
- for(auto tmp:st[u])
- st[v].insert(tmp);
- }
- }
- int main(){
- ios::sync_with_stdio(false);
- cin>>n>>m;
- while (n--){
- cin>>s1>>s>>s>>s>>s2;
- if(!mp.count(s1))mp[s1]=cnt++;
- if(!mp.count(s2))mp[s2]=cnt++;
- g[mp[s2]].push_back(mp[s1]);
- }
- for(int i=;i<cnt;i++){
- if(!vis[i])
- dfs(i);
- }
- while (m--){
- cin>>s1>>s>>s>>s>>s2;
- if(!mp.count(s1)||!mp.count(s2)){
- cout<<"Pants on Fire"<<endl;
- } else{
- if(st[mp[s2]].count(mp[s1])){
- cout<<"Fact"<<endl;
- } else if(st[mp[s1]].count(mp[s2])){
- cout<<"Alternative Fact"<<endl;
- } else{
- cout<<"Pants on Fire"<<endl;
- }
- }
- }
- }
G:现学的那个什么皮克公式。好神奇啊!虽然不知道为什么。然后仔细读题会发现他给你的点是按顺序的。算一下叉积就完了。可以百度 皮克公式呀qwq
- #include <bits/stdc++.h>
- #define mk(a,b) make_pair(a,b)
- #define pii pair<int,int>
- using namespace std;
- typedef long long ll;
- int n;
- struct point{
- ll x,y;
- }p[];
- ll cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}
- ll gcd(ll a,ll b){
- a=abs(a);b=abs(b);
- if(a==)return b;
- if(b==)return a;
- return __gcd(a,b);
- }
- int main(){
- //ios::sync_with_stdio(false);
- scanf("%d",&n);
- for(int i=;i<n;i++)
- scanf("%lld%lld",&p[i].x,&p[i].y);
- ll S=,cnt=;
- for(int i=;i<n;i++){
- S+=cross(p[i],p[(i+)%n]);
- }
- S/=;
- S=abs(S);
- for(int i=;i<n;i++){
- cnt+=gcd(p[i].x-p[(i+)%n].x,p[i].y-p[(i+)%n].y);
- }
- ll a = S-cnt/+;
- printf("%lld\n",a);
- }
- /**
- 4
- 0 0
- 0 10
- 10 10
- 10 0
- 4
- 0 3
- 3 0
- 0 -1
- -1 0
- */
F:哇上来我一看,这直接枚举不就完了吗!TLE ON TEST 8。说好的玄学复杂度呢呜呜呜 自闭。 后来想到会有大量重复的过程,,但是我学艺不精,写的最大流,就不会改了。。昨天看了题解!
哇!二分图匹配,然后每个点再做两次增广!用另外一个数组把一开始的存下来。草!这题竟该死的巧妙。匈牙利大法好哇。
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5+;
- const int INF = 0x3f;
- struct Edge{
- int u,v,nxt;
- Edge(int u=,int v=,int nxt=):u(u),v(v),nxt(nxt){}
- }edge[*N];
- int n,m,k,cnt;
- int head[N],d[N],c[N];
- void addEdge(int u,int v){
- edge[++cnt]=Edge(u,v,head[u]);
- head[u]=cnt;
- }
- int match[N],vis[N],tmp[N];
- bool dfs(int u){
- for(int i=head[u];~i;i=edge[i].nxt){
- int v = edge[i].v;
- if(vis[v])continue;
- vis[v]=;
- if(match[v]==-||dfs(match[v])){
- match[v]=u;
- return true;
- }
- }
- return false;
- }
- void init(){
- memset(head,-, sizeof(head));
- cnt=;
- }
- int main(){
- ios::sync_with_stdio(false);
- init();
- scanf("%d%d%d",&n,&m,&k);
- int u,v;
- for(int i=;i<=k;i++){
- scanf("%d%d",&u,&v);
- addEdge(u,v);
- }
- int mx=;
- memset(match,-, sizeof(match));
- for(int i=;i<=n;i++){
- memset(vis,, sizeof(vis));
- if(dfs(i))mx++;
- }
- memcpy(tmp,match,sizeof(match));
- int ans =;
- for(int i=;i<=n;i++){
- int num=;
- while (dfs(i)&&num<){
- memset(vis,, sizeof(vis));
- num++;
- }
- ans=max(ans,num);
- memcpy(match,tmp, sizeof(tmp));
- }
- printf("%d\n",ans+mx);
- }
I:签到
- #include <bits/stdc++.h>
- #define mk(a,b) make_pair(a,b)
- #define pii pair<int,int>
- using namespace std;
- typedef long long ll;
- const int N = 3e5+;
- int n,m;
- int a[N],dp[N][];
- int main(){
- ios::sync_with_stdio(false);
- cin>>n>>m;
- for(int i=;i<=n;i++)cin>>a[i];
- for(int i=m+;i<=n;i++){
- dp[i][]=max(dp[i-m][],dp[i-m][])+a[i];
- dp[i][]=max(dp[i-][],dp[i-][]);
- }
- cout<<max(dp[n][],dp[n][]);
- }
K:签到
- #include <bits/stdc++.h>
- #define mk(a,b) make_pair(a,b)
- #define pii pair<int,int>
- using namespace std;
- typedef long long ll;
- int n,d,k;
- struct Node{
- string s;
- int c;
- bool operator < (const Node& a)const {
- return c<a.c;
- }
- };
- priority_queue<Node> q;
- vector<string>ans;
- int main(){
- ios::sync_with_stdio(false);
- cin>>n>>d>>k;
- string s;int c;
- while (n--){
- cin>>s>>c;
- q.push(Node{s,c});
- }
- int sum=;
- while (!q.empty()&&sum<d){
- sum+=q.top().c;
- ans.push_back(q.top().s);
- q.pop();
- }
- if(ans.size()>k||sum<d){
- cout<<"impossible"<<endl;
- } else{
- cout<<ans.size()<<endl;
- for(auto s:ans){
- cout<<s<< ", YOU ARE FIRED!"<<endl;
- }
- }
- }
gym 101873的更多相关文章
- gym/101873/GCPC2017
题目链接:https://codeforces.com/gym/101873 C. Joyride 记忆化搜索形式的dp #include <algorithm> #include < ...
- Gym 101873F Plug It In(二分图匹配)
题目链接:http://codeforces.com/gym/101873/problem/F 题意:有n个插孔,m个机器,和一个插板,一个插孔可以连接一个机器,插板可以使一个插孔连接三个机器,找到最 ...
- Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra]
题目链接:http://codeforces.com/gym/101873/problem/C 题意: 这是七月的又一个阳光灿烂的日子,你决定和你的小女儿一起度过快乐的一天.因为她真的很喜欢隔壁镇上的 ...
- Gym 101873D - Pants On Fire - [warshall算法求传递闭包]
题目链接:http://codeforces.com/gym/101873/problem/D 题意: 给出 $n$ 个事实,表述为 "XXX are worse than YYY" ...
- Gym 101873G - Water Testing - [皮克定理]
题目链接:http://codeforces.com/gym/101873/problem/G 题意: 在点阵上,给出 $N$ 个点的坐标(全部都是在格点上),将它们按顺序连接可以构成一个多边形,求该 ...
- Gym 101873I - Uberwatch - [DP]
题目链接:http://codeforces.com/gym/101873/problem/I 题意: 给出 $n(1 \le n \le 300000)$ 个单位时间,每个单位时间给出一个 $x_i ...
- Gym 101873K - You Are Fired - [贪心水题]
题目链接:http://codeforces.com/gym/101873/problem/K 题意: 现在给出 $n(1 \le n \le 1e4)$ 个员工,最多可以裁员 $k$ 人,名字为 $ ...
- codeforces gym #101873B. Buildings(Polya定理)
参考博客: https://blog.csdn.net/liangzhaoyang1/article/details/72639208 题目链接: https://codeforces.com/gym ...
- Joyride (spaf)
题目链接:https://codeforces.com/gym/101873/problem/C spaf的复杂度有点迷,按道理来说,一个简单的spaf在这题的复杂度是1e9,所以不敢写,然后用优先队 ...
随机推荐
- Android定制:修改开机启动画面
转自:https://blog.csdn.net/godiors_163/article/details/72529210 引言 Android系统在按下开机键之后就会进入启动流程,这个过程本身需要一 ...
- Linux脚本程序
#!/bin/bash # array-ops.sh: 数组更多有趣的用法. array=( zero one two three four five ) # 元素 ]} # zero } # zer ...
- C# Task ContinueWith的实现
看了上一篇C# Task 是什么?返回值如何实现? Wait如何实现 我们提到FinishContinuations方法中会调用TaskContinuation实例,那么我们的ContinueWith ...
- [Python设计模式] 第17章 程序中的翻译官——适配器模式
github地址:https://github.com/cheesezh/python_design_patterns 适配器模式 适配器模式,将一个类的接口转换成客户希望的另外一个接口.Adapte ...
- Hadoop小文件存储方案
原文地址:https://www.cnblogs.com/ballwql/p/8944025.html HDFS总体架构 在介绍文件存储方案之前,我觉得有必要先介绍下关于HDFS存储架构方面的一些知识 ...
- [转]如何实现一个malloc
任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉.但是,许多程序员对malloc背后的事情并不熟悉,许多人甚至 ...
- 初识go的tomb包
在分析github.com/hpcloud/tail 这个包的源码的时候,发现这个包里用于了一个另外一个包,自己也没有用过,但是这个包在tail这个包里又起来非常大的作用 当时并没有完全弄明白这个包的 ...
- Delphi调用java so
package hardware.print; public class printer { static public native int Open(); } jni导出的函数是 Java_har ...
- 流媒体之HLS——综述
[时间:2018-01] [状态:Open] [关键词:流媒体,stream,HLS] 0 HLS背景及初衷 HLS是由苹果公司发起的流媒体网络传输协议,可参考rfc8261 HTTP Live St ...
- Object type TYPE failed to create with error
ORA-39083: Object type TYPE failed to create with error: ORA-02304: invalid object identifier litera ...