3.26

http://codeforces.com/gym/101196/attachments

A題

B題

題意:一群人玩桌上足球(>4人),分成黑白兩隊,每隊有進攻和防守兩名玩家,如果有一方失敗則失敗方的防守坐到等候席的結尾、進攻被流放到防守區再上來一個人作為進攻方。而勝利方則是攻防對換。問上場時間最長的有哪些隊伍?打印隊伍的最初狀態的姓名(先打印進攻方后打印防守方)。

思路:首先把所有玩家放入隊列中,然后求出在場上時間最長的隊伍是在第幾輪比賽時入場的放入數組中。然后依次模擬比賽,當模擬到數組中的輪數時就打印此時的隊伍狀態。

  1 #include <iostream>
  2 #include<bits/stdc++.h>
  3 #include<string>
  4 using namespace std;
  5 string p[12],s,ss;
  6 queue<string>que;
  7 string now[2][2];
  8 int a[1005];
  9 int main()
 10 {
 11     int n;
 12     while(cin>>n)
 13     {
 14         while(!que.empty())
 15             que.pop();
 16         for(int i=1; i<=n; i++)
 17         {
 18             cin>>s;
 19             que.push(s);
 20         }
 21         cin>>s;
 22         int len=s.length();
 23         int maxn=0;
 24         int t=0;
 25         for(int i=0; i<len;)
 26         {
 27             int k=i+1,num=0;
 28             while(s[k]==s[i])
 29             {
 30                 num++;
 31                 k++;
 32             }
 33             if(maxn<num)
 34             {
 35                 maxn=num;
 36                 t=0;
 37                 a[t++]=i;
 38             }
 39             else if(maxn==num)
 40             {
 41                 a[t++]=i;
 42             }
 43             i=k;
 44         }
 45         int p=t;
 46         for(int i=0; i<2; i++)
 47             for(int j=0; j<2; j++)
 48             {
 49                 now[j][i]=que.front();
 50                 que.pop();
 51             }
 52         t=0;
 53         for(int i=0; i<len; i++)
 54         {
 55             //cout<<now[0][0]<<" "<<now[0][1]<<endl;
 56             //cout<<now[1][0]<<" "<<now[1][1]<<endl;
 57             if(s[i]=='W')
 58             {
 59                 ss=now[0][0];
 60                 now[0][0]=now[0][1];
 61                 now[0][1]=ss;
 62                 que.push(now[1][1]);
 63                 now[1][1]=now[1][0];
 64                 now[1][0]=que.front();
 65                 que.pop();
 66             }
 67             else if(s[i]=='B')
 68             {
 69                 ss=now[1][0];
 70                 now[1][0]=now[1][1];
 71                 now[1][1]=ss;
 72                 que.push(now[0][1]);
 73                 now[0][1]=now[0][0];
 74                 now[0][0]=que.front();
 75                 //cout<<que.front()<<endl;
 76                 que.pop();
 77             }
 78             if(i==a[t]&&t<p)
 79             {
 80                 if(i==0)
 81                 {
 82                     if(s[i]=='W')
 83                     {
 84                         cout<<now[0][1]<<" "<<now[0][0]<<endl;
 85                     }
 86                     else
 87                     {
 88                         cout<<now[1][1]<<" "<<now[1][0]<<endl;
 89                     }
 90                     t++;
 91                 }
 92                 else
 93                 {
 94                     if(s[i]=='W')
 95                     {
 96                         cout<<now[0][0]<<" "<<now[0][1]<<endl;
 97                     }
 98                     else
 99                     {
100                         cout<<now[1][0]<<" "<<now[1][1]<<endl;
101                     }
102                     t++;
103                 }
104             }
105         }
106 
107     }
108     return 0;
109 }
View Code

C題

題意:給你兩組字符串,一組是加密之后的字符串,一組是加密的前len個密文,從len+1開始密文為原文從第一個,len+2的密文為原文第二個,以此類推,問原文是什么?

思路:前len個原文字符是(s[i]-key[i]+26)%26,后面的是(s[i]-ans[i-len]+26)%26,跑一遍就能得到結果ans了

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 char ch[1005],ans[1005],tmp[1005];
 6 
 7 int main()
 8 {
 9     
10     while(scanf("%s",ch)!=-1)
11     {
12         scanf("%s",tmp);
13         int len1=strlen(ch);
14         int len2=strlen(tmp);
15         for(int i=0;i<len2;i++)
16         {
17             ans[i]=(ch[i]-tmp[i]+26)%26+'A';
18         }
19         for(int i=len2;i<len1;i++)
20         {
21             ans[i]=(ch[i]-ans[i-len2]+26)%26+'A';
22         }
23         ans[len1]='\0';
24         printf("%s\n",ans);
25 
26     }
27     return 0;
28 }
View Code

D題

E題

題意:問一個字符串多個相同的子串組成,將相同子串變成一個單字符M,變完之后的字符串長度加上子串的長度的最小值是多少?

思路:由于所給字符串較短,直接暴力求解。求長度為從1~len/2的所有子串,然后依次于主串進行匹配,更新的最小結果即可。

 1 #include <iostream>
 2 #include<bits/stdc++.h>
 3 #include<string>
 4 using namespace std;
 5 string s;
 6 string c[105][105];
 7 map<string,int > mp;
 8 int main()
 9 {
10     while(cin>>s)
11     {
12         int len=s.size();
13         int ans=len;
14         for(int i=1; i<len; i++)
15         {
16             for(int j=0; j<len-i; j++)
17             {
18                 string ch=s.substr(j,i);
19                 int tmp=0;
20                 for(int k=0;k<=len-i;)
21                 {
22                     string p=s.substr(k,i);
23                     if(p==ch)
24                     {
25                         tmp++;
26                         k=k+i;
27                     }
28                     else
29                         k++;
30                 }
31                 if(ans>len-tmp*(ch.size()-1)+ch.size())
32                     ans=len-tmp*(ch.size()-1)+ch.size();
33             }
34         }
35         cout<<ans<<endl;
36     }
37     return 0;
38 }
View Code

F題

G題

H題

題意:給兩個凸多邊形的邊界,問這兩個凸多邊形有多少個點只包含在A內部,又有多少個點包含在B的內部,還有多少個點包含在A和B的內部(不含邊界點)。

思路:從A點開始進行搜索邊界,并在標記數組vis1中進行記錄,同理對B進行處理記錄在vis2中,然后對vis1和vis2的外圍進行標記覆蓋,最后取得圖上的字符是點的vis1或vis2為0的結果。

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <algorithm>
  4 #include <cmath>
  5 #include <iostream>
  6 #include <vector>
  7 #include <queue>
  8 #include <string>
  9 #include <set>
 10 #include <stack>
 11 #include <map>
 12 using namespace std;
 13 const int maxn = 105;
 14 int vis[maxn][maxn];
 15 int vis1[maxn][maxn];
 16 int vis2[maxn][maxn];
 17 char a[maxn][maxn];
 18 int n,m;
 19 int dx[] = {0,0,1,-1,};
 20 int dy[] = {1,-1,0,0,};
 21 void colorA(int i,int j,int clo);
 22 void dfsA(int i,int j,int dir,int clo);
 23 void colorB(int i,int j,int clo);
 24 void dfsB(int i,int j,int dir,int clo);
 25 void dfs(int i,int j,int clo,int vis[105][105])
 26 {
 27     for(int k=0;k<4;k++)
 28     {
 29         int tx = i+dx[k];
 30         int ty = j+dy[k];
 31         if(vis[tx][ty])
 32             continue;
 33         if(tx<0 || ty<0 || tx>n+1 || ty>m+1)
 34             continue;
 35         vis[tx][ty] = clo;
 36         dfs(tx,ty,clo,vis);
 37     }
 38 }
 39 bool checkA(int i,int j)
 40 {
 41     if(i<0||j<0||i>n||j>m)
 42         return false;
 43     if(vis1[i][j]==1)
 44         return false;
 45     return a[i][j]=='X'||a[i][j]=='A';
 46 }
 47 bool checkB(int i,int j)
 48 {
 49     if(i<0||j<0 || i>n+1 || j>m+1)
 50         return false;
 51     if(vis2[i][j]==2)
 52         return false;
 53     return a[i][j]=='X'||a[i][j]=='B';
 54 }
 55 void colorA(int i,int j,int clo)
 56 {
 57     if(checkA(i,j+1))
 58         dfsA(i,j+1,0,clo);
 59     else if(checkA(i,j-1))
 60         dfsA(i,j-1,1,clo);
 61     else if(checkA(i+1,j))
 62         dfsA(i+1,j,2,clo);
 63     else if(checkA(i-1,j))
 64         dfsA(i-1,j,3,clo);
 65 }
 66 void colorB(int i,int j,int clo)
 67 {
 68     if(checkB(i,j+1))
 69         dfsB(i,j+1,0,clo);
 70     else if(checkB(i,j-1))
 71         dfsB(i,j-1,1,clo);
 72     else if(checkB(i+1,j))
 73         dfsB(i+1,j,2,clo);
 74     else if(checkB(i-1,j))
 75         dfsB(i-1,j,3,clo);
 76 }
 77 void dfsA(int i,int j,int dir,int clo)
 78 {
 79     vis1[i][j] = clo;
 80     if(checkA(i+dx[dir],j+dy[dir]))
 81         dfsA(i+dx[dir],j+dy[dir],dir,clo);
 82     else
 83         colorA(i,j,clo);
 84 }
 85 void dfsB(int i,int j,int dir,int clo)
 86 {
 87     vis2[i][j] = clo;
 88     if(checkB(i+dx[dir],j+dy[dir]))
 89         dfsB(i+dx[dir],j+dy[dir],dir,clo);
 90     else
 91         colorB(i,j,clo);
 92 }
 93 int main()
 94 {
 95     memset(vis,0,sizeof(vis));
 96     memset(vis1,0,sizeof(vis1));
 97     memset(vis2,0,sizeof(vis2));
 98     scanf("%d %d",&n,&m);
 99     for(int i=0;i<=n;i++)
100         a[n+1][i] = a[i][m+1] = a[0][i] = a[i][0] = '.';
101     for(int i=1;i<=n;i++)
102         scanf("%s",a[i]+1);
103     int ax,ay,bx,by;
104     for(int i=0;i<=n;i++)
105     {
106         for(int j=0;j<=m;j++)
107         {
108             if(a[i][j]=='A')
109                 ax=i,ay=j;
110             if(a[i][j]=='B')
111                 bx=i,by=j;
112         }
113     }
114     colorA(ax,ay,1);
115     colorB(bx,by,2);
116     vis1[0][0] = 6;
117     vis2[0][0] = 6;
118     dfs(0,0,6,vis1);
119     dfs(0,0,6,vis2);
120     for(int i=0;i<=n;i++)
121     {
122         for(int j=0;j<=m;j++)
123         {
124             if(vis1[i][j]==0 && a[i][j]=='.')
125                 vis1[i][j] = 3;
126             if(vis2[i][j]==0 && a[i][j]=='.')
127                 vis2[i][j] = 4;
128         }
129     }
130 //    for(int i=0;i<=n;i++)
131 //    {
132 //        for(int j=0;j<=m;j++)
133 //            printf("%d ",vis1[i][j]);
134 //        puts("");
135 //    }
136 //    puts("");
137 //    for(int i=0;i<=n;i++)
138 //    {
139 //        for(int j=0;j<=m;j++)
140 //            printf("%d ",vis2[i][j]);
141 //        puts("");
142 //    }
143     int ans1 = 0,ans2 = 0,ans3 = 0;
144     for(int i=0;i<=n;i++)
145     {
146         for(int j=0;j<=m;j++)
147         {
148             if(vis1[i][j]==3&&a[i][j]=='.')
149                 ans1++;
150             if(vis2[i][j]==4&&a[i][j]=='.')
151                 ans2++;
152             if(vis1[i][j]==3&&vis2[i][j]==4&&a[i][j]=='.')
153                 ans3++;
154         }
155     }
156     printf("%d %d %d\n",ans1-ans3,ans2-ans3,ans3);
157     return 0;
158 }
View Code

I題

J題

?

轉載于:https://www.cnblogs.com/wang-ya-wei/p/6647139.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/371188.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/371188.shtml
英文地址,請注明出處:http://en.pswp.cn/news/371188.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

scala akka通信機制

https://www.2cto.com/kf/201701/587514.html轉載于:https://www.cnblogs.com/rocky-AGE-24/p/7542874.html

JUnit通過失敗測試案例

為什么要建立一種預期測試失敗的機制&#xff1f; 有一段時間&#xff0c;人們會希望并期望JUnit Test案例失敗。 盡管這種情況很少見&#xff0c;但確實發生了。 我需要檢測JUnit測試何時失敗&#xff0c;然后&#xff08;如果期望的話&#xff09;通過而不是失敗。 具體情況是…

CentOS6.5安裝MySQL5.7詳細教程

CentOS6.5安裝MySQL5.7詳細教程 注&#xff1a;文中所寫的安裝過程均在CentOS6.5 x86下通過測試 主要參考博文&#xff1a; https://segmentfault.com/a/1190000003049498 http://www.th7.cn/db/mysql/201601/175073.shtml 1.檢測系統是否已經安裝過mysql或其依賴&#xff0c;若…

cmake 查看編譯命令,以及在vscode中如何使用cmke

通過設置如下配置選項&#xff0c;可以生成compile_commands.json 文件&#xff0c;記錄使用的編譯命令 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)獲得現有模塊列表 cmake --help-module-list查看命令文檔 cmake --help-command find_file查看模塊的詳細信息 cmake --help-mo…

php學習八:封裝

一&#xff1a;在php中&#xff0c;用class關鍵字來創建一個類&#xff0c;即進行封裝&#xff1b;在類里面有成員屬性和方法行為組成&#xff1a; 1.成員屬性:用關鍵字var來聲明,可以給初始值也可以不給;現在var廢棄&#xff0c;用public來聲明&#xff0c;public為共有屬性&a…

純Java JavaFX 2.0菜單

在有關JavaFX的最新文章中 &#xff0c;我集中討論了不使用JavaFX 1.x的JavaFXScript和不使用JavaFX 2.0的新FXML來使用JavaFX 2.0的新Java API 。 所有這些示例均已使用標準Java編譯器進行了編譯&#xff0c;并使用標準Java啟動 器執行。 在本文中&#xff0c;我將繼續演示使用…

設置QtreeWidget水平滾動條

轉載請注明出處&#xff1a;http://www.cnblogs.com/dachen408/p/7552603.html //設置treewidget水平滾動條 ui.treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);ui.treeWidget->header()->setStretchLastSection(false);轉載于:https…

java 序列化 uid,Java中的序列化版本uid

How is Serialization id stored in the instance of the object ?The Serialization id we declare in Java is static field;and static fields are not serialized.There should be some way to store the static final field then. How does java do it ?解決方案The ser…

HTML5本地存儲

什么是Web Storage Web Storage是HTML5里面引入的一個類似于cookie的本地存儲功能&#xff0c;可以用于客戶端的本地存儲&#xff0c;其相對于cookie來說有以下幾點優勢&#xff1a; 存儲空間大&#xff1a;cookie只有4KB的存儲空間&#xff0c;而Web Storage在官方建議中為每個…

番石榴秒表

番石榴的秒表是番石榴第10版的另一個新番石榴類&#xff08;作為Optional &#xff0c;這是另一篇近期文章的主題&#xff09;。 顧名思義&#xff0c;這個簡單的類提供了一種方便地測量兩個代碼點之間經過的時間的方法。 與使用System.currentTimeMillis&#xff08;&#xff…

CF 839 E-最大團

CF 839 E Soltion: 就是怎么求最大團的問題: 以下是\(O(7000\times n^2)\)的做法 求一個最大團,然后將所有的藥水平均分配,到最大團的所有點上,計算答案. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorit…

sse java_SSE詳解

SSE(Server-Sent Events):通俗解釋起來就是一種基于HTTP的&#xff0c;以流的形式由服務端持續向客戶端發送數據的技術應用場景由于HTTP是無狀態的傳輸協議,每次請求需由客戶端向服務端建立連接,HTTPS還需要交換秘鑰&#xff0c;所以一次請求,建立連接的過程占了很大比例在http…

520. Detect Capital

題目&#xff1a; Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like "USA".A…

盒模型的屬性丶display顯示丶浮動

一丶盒模型的屬性(重要) 1.padding padding是標準文檔流,父子之間調整位置 <!DOCTYPE html><html><head><meta charset"UTF-8"><title>padding</title><style>*{padding: 0;margin: 0;}.box{width: 200px;height: 200px;b…

MapReduce:通過數據密集型文本處理

自上次發布以來已經有一段時間了&#xff0c;因為我一直在忙于Coursera提供的一些課程。 有一些非常有趣的產品&#xff0c;值得一看。 前一段時間&#xff0c;我購買了Jimmy Lin和Chris Dyer的MapReduce數據密集型處理程序 。 本書以偽代碼格式介紹了幾種關鍵的MapReduce算法。…

ubuntu(deepin)安裝apache2并支持php7.0

linux虛擬機下用于開發環境測試&#xff0c;安裝的apache和php7.0&#xff0c;但是簡單安裝完兩者后apache并不能解析php&#xff0c;原因是確實apache的php擴展。 # 首先安裝apache sudo apt-get install apache2 # 然后安裝php7.0 sudo apt-get install php7.0 # 一般執行完這…

java applet 換行_Java復習題

一、選擇題1.有Java語句如下&#xff0c;則說法正確的是()A.此語句是錯誤的B. a.length的值為5C. b.length的值為5D. a.length和b.length的值都為52.整數除法中&#xff0c;如果除數為0&#xff0c;則將導致的異常是( B )A. NullPointerExceptionB. ArithmeticExceptionC. Arra…

解決:MVC對象轉json包含\r \n

項目中對象轉json字符串時&#xff0c;如下&#xff1a;JsonSerializerSettings jsetting new JsonSerializerSettings(); jsetting.DefaultValueHandling DefaultValueHandling.Ignore; return JsonConvert.SerializeObject(resultMoldels, Formatting.Indented, jsetting);…

CSS 小結筆記之滑動門技術

所謂的滑動門技術&#xff0c;就是指盒子背景能夠自動拉伸以適應不同長度的文本。即當文字增多時&#xff0c;背景看起來也會變長。 大多數應用于導航欄之中&#xff0c;如微信導航欄: 具體實現方法如下&#xff1a; 1、首先每一塊文本內容是由a標簽與span標簽組成 <a hr…

使用API??身份驗證的Spring Security

背景 盡管有許多博客文章詳細介紹了如何使用Spring Security&#xff0c;但是當問題域位于標準LDAP或數據庫身份驗證之外時&#xff0c;我仍然經常發現配置挑戰。 在本文中&#xff0c;我將介紹一些針對Spring Security的簡單自定義&#xff0c;使其能夠與基于REST的API調用一起…