• 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[1005];
    int t[1005],p[1005],dis[1005][1005];
    void Dijkstra(){
        for(int i=1;i<=n;i++)for(int j=1;j<=x;j++)dis[i][j]=2147483647;
        if(t[1]>x)return;
        dis[1][t[1]]=p[1];
        priority_queue<node>Q;
        Q.push(node{1,t[1],p[1]});
        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=1;i<=m;i++){
            cin>>a>>b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        for(int i=1;i<=n;i++){
            cin>>t[i]>>p[i];
        }
        Dijkstra();
        if(dis[1][x]==2147483647)cout<<"It is a trap."<<endl;
        else cout<<dis[1][x]<<endl;
    }
    View Code

    D:签到,我写的很傻逼

     1 #include <bits/stdc++.h>
     2 #define mk(a,b) make_pair(a,b)
     3 #define pii pair<int,int>
     4 using namespace std;
     5 typedef long long ll;
     6 string s1,s2,s;
     7 int n,m,cnt=0,vis[255];
     8 map<string,int>mp;
     9 vector<int>g[255];
    10 set<int> st[205];
    11 void dfs(int v){
    12     st[v].insert(v);
    13     for(auto u:g[v]){
    14         dfs(u);
    15         for(auto tmp:st[u])
    16             st[v].insert(tmp);
    17     }
    18 }
    19 int main(){
    20     ios::sync_with_stdio(false);
    21     cin>>n>>m;
    22     while (n--){
    23         cin>>s1>>s>>s>>s>>s2;
    24         if(!mp.count(s1))mp[s1]=cnt++;
    25         if(!mp.count(s2))mp[s2]=cnt++;
    26         g[mp[s2]].push_back(mp[s1]);
    27     }
    28     for(int i=1;i<cnt;i++){
    29         if(!vis[i])
    30             dfs(i);
    31     }
    32     while (m--){
    33         cin>>s1>>s>>s>>s>>s2;
    34         if(!mp.count(s1)||!mp.count(s2)){
    35             cout<<"Pants on Fire"<<endl;
    36         } else{
    37             if(st[mp[s2]].count(mp[s1])){
    38                 cout<<"Fact"<<endl;
    39             } else if(st[mp[s1]].count(mp[s2])){
    40                  cout<<"Alternative Fact"<<endl;
    41             } else{
    42                 cout<<"Pants on Fire"<<endl;
    43             }
    44         }
    45     }
    46 }
    View Code

    G:现学的那个什么皮克公式。好神奇啊!虽然不知道为什么。然后仔细读题会发现他给你的点是按顺序的。算一下叉积就完了。可以百度 皮克公式呀qwq

     1 #include <bits/stdc++.h>
     2 #define mk(a,b) make_pair(a,b)
     3 #define pii pair<int,int>
     4 using namespace std;
     5 typedef long long ll;
     6 int n;
     7 struct point{
     8     ll x,y;
     9 }p[100005];
    10 ll cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}
    11 ll gcd(ll a,ll b){
    12     a=abs(a);b=abs(b);
    13     if(a==0)return b;
    14     if(b==0)return a;
    15     return __gcd(a,b);
    16 }
    17 int main(){
    18     //ios::sync_with_stdio(false);
    19     scanf("%d",&n);
    20     for(int i=0;i<n;i++)
    21         scanf("%lld%lld",&p[i].x,&p[i].y);
    22     ll S=0,cnt=0;
    23     for(int i=0;i<n;i++){
    24         S+=cross(p[i],p[(i+1)%n]);
    25     }
    26     S/=2;
    27     S=abs(S);
    28     for(int i=0;i<n;i++){
    29         cnt+=gcd(p[i].x-p[(i+1)%n].x,p[i].y-p[(i+1)%n].y);
    30     }
    31     ll a = S-cnt/2+1;
    32     printf("%lld
    ",a);
    33 }
    34 /**
    35 4
    36 0 0
    37 0 10
    38 10 10
    39 10 0
    40 
    41 4
    42 0 3
    43 3 0
    44 0 -1
    45 -1 0
    46  */
    View Code

    F:哇上来我一看,这直接枚举不就完了吗!TLE ON TEST 8。说好的玄学复杂度呢呜呜呜  自闭。 后来想到会有大量重复的过程,,但是我学艺不精,写的最大流,就不会改了。。昨天看了题解!

    哇!二分图匹配,然后每个点再做两次增广!用另外一个数组把一开始的存下来。草!这题竟该死的巧妙。匈牙利大法好哇。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int N = 1e5+7;
     4 const int INF = 0x3f;
     5 struct Edge{
     6     int u,v,nxt;
     7     Edge(int u=0,int v=0,int nxt=0):u(u),v(v),nxt(nxt){}
     8 }edge[30*N];
     9 int n,m,k,cnt;
    10 int head[N],d[N],c[N];
    11 void addEdge(int u,int v){
    12     edge[++cnt]=Edge(u,v,head[u]);
    13     head[u]=cnt;
    14 }
    15 int match[N],vis[N],tmp[N];
    16 bool dfs(int u){
    17     for(int i=head[u];~i;i=edge[i].nxt){
    18         int v = edge[i].v;
    19         if(vis[v])continue;
    20         vis[v]=1;
    21         if(match[v]==-1||dfs(match[v])){
    22             match[v]=u;
    23             return true;
    24         }
    25     }
    26     return false;
    27 }
    28 void init(){
    29     memset(head,-1, sizeof(head));
    30     cnt=1;
    31 }
    32 int main(){
    33     ios::sync_with_stdio(false);
    34     init();
    35     scanf("%d%d%d",&n,&m,&k);
    36     int u,v;
    37     for(int i=1;i<=k;i++){
    38         scanf("%d%d",&u,&v);
    39         addEdge(u,v);
    40     }
    41     int mx=0;
    42     memset(match,-1, sizeof(match));
    43     for(int i=1;i<=n;i++){
    44         memset(vis,0, sizeof(vis));
    45         if(dfs(i))mx++;
    46     }
    47     memcpy(tmp,match,sizeof(match));
    48     int ans =0;
    49     for(int i=1;i<=n;i++){
    50         int num=0;
    51         while (dfs(i)&&num<2){
    52             memset(vis,0, sizeof(vis));
    53             num++;
    54         }
    55         ans=max(ans,num);
    56         memcpy(match,tmp, sizeof(tmp));
    57     }
    58     printf("%d
    ",ans+mx);
    59 }
    View Code

    I:签到

     1 #include <bits/stdc++.h>
     2 #define mk(a,b) make_pair(a,b)
     3 #define pii pair<int,int>
     4 using namespace std;
     5 typedef long long ll;
     6 const int N = 3e5+5;
     7 int n,m;
     8 int a[N],dp[N][2];
     9 int main(){
    10     ios::sync_with_stdio(false);
    11     cin>>n>>m;
    12     for(int i=1;i<=n;i++)cin>>a[i];
    13     for(int i=m+1;i<=n;i++){
    14         dp[i][1]=max(dp[i-m][1],dp[i-m][0])+a[i];
    15         dp[i][0]=max(dp[i-1][1],dp[i-1][0]);
    16     }
    17     cout<<max(dp[n][0],dp[n][1]);
    18 }
    View Code

    K:签到

     1 #include <bits/stdc++.h>
     2 #define mk(a,b) make_pair(a,b)
     3 #define pii pair<int,int>
     4 using namespace std;
     5 typedef long long ll;
     6 int n,d,k;
     7 struct Node{
     8     string s;
     9     int c;
    10     bool operator < (const Node& a)const {
    11         return c<a.c;
    12     }
    13 };
    14 priority_queue<Node> q;
    15 vector<string>ans;
    16 int main(){
    17     ios::sync_with_stdio(false);
    18     cin>>n>>d>>k;
    19     string s;int c;
    20     while (n--){
    21         cin>>s>>c;
    22         q.push(Node{s,c});
    23     }
    24     int sum=0;
    25     while (!q.empty()&&sum<d){
    26         sum+=q.top().c;
    27         ans.push_back(q.top().s);
    28         q.pop();
    29     }
    30     if(ans.size()>k||sum<d){
    31         cout<<"impossible"<<endl;
    32     } else{
    33         cout<<ans.size()<<endl;
    34         for(auto s:ans){
    35             cout<<s<< ", YOU ARE FIRED!"<<endl;
    36         }
    37     }
    38 }
    View Code
  • 相关阅读:
    SpringBoot第五篇:整合Mybatis
    SpringBoot第四篇:整合JDBCTemplate
    SpringBoot第三篇:配置文件详解二
    分享一篇去年的项目总结
    Oracle生成多表触发器sql
    Oracle 设置用户密码永不过期
    Oracle建表提示SQL 错误: ORA-00904: : 标识符无效
    MySql数据备份
    ETL全量多表同步简述
    ETL全量单表同步简述
  • 原文地址:https://www.cnblogs.com/MXang/p/10352681.html
Copyright © 2020-2023  润新知