Summer training #2
A:不管有没有负数 一顿操作之后肯定只有正数 又因为A=A-B 所以最大值是一直在减小的 所以一定有结果
B:..一开始以为求min操作数 WA了2发 直接求所有数的GCD如果所有数的GCD都不是1的话就无解 有解就无脑扫2次就好了
C:给你一个char正方形矩阵 要求a[i][j]四个正方形对称轴都一样 可以任意change 直接爆搜八分之一块就行了.
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
int cmp(int a,int b)
{
return a<b;
}
char s[][];
int visit[][];
int gcd1(int a, int b)
{ return a == ? b : gcd1(b % a, a); }
map<char,int> mp;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t;
cin >> t;
while(t--)
{
int anser=;
int n;
char ch;
cin >> n;
int mid=(n+)/;
for(int i=;i<=n;i++)
mem(visit[i],);
for(int i=;i<=n;i++)
{
scanf("%s",s[i]+);
}
/*for(int i=1;i<=n;i++)
{
printf("%s\n",s[i]+1);
}*/
int maxn=;
for(int i=;i<=(n+)/;i++)
for(int j=;j<=(n+)/;j++)
{
if(visit[i][j]==)
continue;
if(i==j&&i+j==n+)
continue;
if(i==j||i+j==n+||*i==n+||*j==n+)
{
int ans=;
mp.clear();
mp[s[i][j]]++;
mp[s[i][n+-j]]++;
mp[s[n+-i][j]]++;
mp[s[n+-i][n+-j]]++;
mp[s[j][i]]++;
mp[s[n+-j][i]]++;
mp[s[j][n+-i]]++;
mp[s[n+-j][n+-i]]++;
visit[i][j]=;
visit[i][n+-j]=;
visit[n+-i][j]=;
visit[n+-i][n+-j]=;
visit[j][i]=;
visit[n+-j][i]=;
visit[j][n+-i]=;
visit[n+-j][n+-i]=;
ans=max(ans,mp[s[i][j]]);
ans=max(ans,mp[s[i][n+-j]]);
ans=max(ans,mp[s[n+-i][j]]);
ans=max(ans,mp[s[n+-i][n+-j]]);
ans=max(ans,mp[s[j][i]]);
ans=max(ans,mp[s[n+-j][i]]);
ans=max(ans,mp[s[j][n+-i]]);
ans=max(ans,mp[s[n+-j][n+-i]]);
//cout <<i << ""<<j<<endl;
//cout<<4-ans/2<<endl;
anser+=-ans/;
}
else
{
int ans=;
mp.clear();
mp[s[i][j]]++;
mp[s[i][n+-j]]++;
mp[s[n+-i][j]]++;
mp[s[n+-i][n+-j]]++;
mp[s[j][i]]++;
mp[s[n+-j][i]]++;
mp[s[j][n+-i]]++;
mp[s[n+-j][n+-i]]++;
visit[i][j]=;
visit[i][n+-j]=;
visit[n+-i][j]=;
visit[n+-i][n+-j]=;
visit[j][i]=;
visit[n+-j][i]=;
visit[j][n+-i]=;
visit[n+-j][n+-i]=;
ans=max(ans,mp[s[i][j]]);
ans=max(ans,mp[s[i][n+-j]]);
ans=max(ans,mp[s[n+-i][j]]);
ans=max(ans,mp[s[n+-i][n+-j]]);
ans=max(ans,mp[s[j][i]]);
ans=max(ans,mp[s[n+-j][i]]);
ans=max(ans,mp[s[j][n+-i]]);
ans=max(ans,mp[s[n+-j][n+-i]]);
//cout <<i << ""<<j<<endl;
//cout <<8-ans<<endl;
anser+=-ans;
}
}
cout << anser<<endl;
}
return ;
}
D:画人脸
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
char ans[][][];
int len1[],len2[];
void init()
{
for(int i=;i<;i++)
for(int j=;j<;j++)
ans[][i][j]='*';
ans[][][]=ans[][][]=ans[][][]=' ';
ans[][][]=ans[][][]=ans[][][]=' ';
ans[][][]=ans[][][]=ans[][][]=' ';
ans[][][]=ans[][][]=ans[][][]=' ';
ans[][][]=ans[][][]=' ';
ans[][][]=ans[][][]=' ';
len1[]=,len2[]=;
for(int i=;i<=;i++)
len1[i]=len1[i-]*+;
for(int i=;i<=;i++)
len2[i]=len2[i-]*+;
}
void draw1(int x,int x1,int y1,int x2,int y2)//y2>y1 x2>x1
{
if(x1==x2)
{
for(int i=y1;i<=y2;i++)
{
ans[x][x1][i]='*';
}
}
else
{
for(int i=x1;i<=x2;i++)
ans[x][i][y1]='*';
}
}
void draw(int x,int len)
{
int jian0=len>>;
int jianer=len>>;
int jianyi=len>>;
draw1(x,,,,len-);
draw1(x,,,len-,);
draw1(x,,len-,len-,len-);
draw1(x,len-,,len-,len-);
//TS;
draw1(x,jianer,jianer,jianer+jianyi-,jianer);
draw1(x,jianer,jianer,jianer,jianer+jianyi-);
draw1(x,jianer+jianyi,jianer,jianer+jianyi,jianer+jianyi-);
draw1(x,jianer,jianer+jianyi-,jianer+jianyi,jianer+jianyi-);
//TS;
draw1(x,jianer,jianer+*jianyi-,jianer,jianer+*jianyi-);
draw1(x,jianer,jianer+*jianyi-,jianer+jianyi,jianer+*jianyi-);
draw1(x,jianer,jianer+*jianyi-,jianer+jianyi,jianer+*jianyi-);
draw1(x,jianer+jianyi,jianer+*jianyi-,jianer+jianyi,jianer+*jianyi-);
//TS;
for(int i=len-;i>=jian0;i--)
for(int j=jianyi+jian0-;j>=jianyi;j--)
{
ans[x][i][j]=ans[x-][len--i][jianyi+jian0--j];
}
//cout << x<<endl;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
init();
//TS;
for(int x=;x<=;x++)
{
draw(x,<<x);
}
while(scanf("%d",&n)==)
{
if(n<)
break;
int num=log2(n);
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
printf("%c",ans[num][i][j]);
}
cout <<endl;
}
cout <<endl;
}
return ;
}
E:先离散化 离散化 +模拟双端队列
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Node{
int c,p;
bool operator<(const Node& rhs)const{
if(c!=rhs.c) return c<rhs.c;
return p<rhs.p;
}
}s[];
int N,K;
int cal(int st,int ed){
int k=,sum=,ret=;
for(int p=st,q=st;q<=ed;){
if(k<=K){
sum++;
ret=max(ret,sum);
k+=s[q+].p-s[q].p-;
q++;
}else{
sum--;
k-=s[p+].p-s[p].p-;
p++;
}
}
return ret;
}
int main()
{
// freopen("data.in","r",stdin);
while(scanf("%d%d",&N,&K)==){
int i,j;
for(i=;i<N;s[i].p=i++)
scanf("%d",&s[i].c);
sort(s,s+N);
int ans=;
for(i=;i<N;i=j+){
int c=s[i].c;
j=i;
while(j+<N && s[j+].c==c) j++;
ans=max(ans,cal(i,j));
}
printf("%d\n",ans);
}
return ;
}
F:递推DP
1)用dp[i][j]表示源串第i次操作后,与目标串不同的位置有几个。
(2)对于dp[i][j],有j个位置与目标串不同,所以可以将j个位置中的t个位置变为与目标串相同,把其余n-j个位置中的m-t个位置变为与目标串不同,转移方程就是dp[i+1][j-t+m-t]+=dp[i][j]*C(t,j)*C(m-t,n-j);
(3)如果j+m>n,那么t就无法从0开始枚举了,所以此时t从(m-(n-j))开始(m次操作中有n-j次操作落在n-j个相同位置的里面,还有m-(n-j)次操作落在j个不同位置的里面)。
(4)初始条件就是用cnt统计源串和目标串有多少个位置不一样,dp[0][cnt]=1,通过dp把路径都找出来,那么答案就是dp[k][0]。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const LL MOD=;
LL dp[][],c[][];
char s[],d[]; void _init(){
c[][]=;
for(int i=;i<=;i++){
c[i][]=;
for(int j=;j<=i;j++){
c[i][j]=(c[i-][j-]+c[i-][j])%MOD;
}
}
} int main()
{
int n,k,m, i,j,t,x;
_init();
while(scanf("%d%d%d",&n,&k,&m)==){
scanf("%s",s);
scanf("%s",d);
x=;
for(i=;i<n;i++)
if(s[i]!=d[i])x++;
for(i=;i<=k;i++)
for(j=;j<=n;j++)
dp[i][j]=;
dp[][x]=;
for(i=;i<k;i++)//ith operation
for(j=;j<=n;j++){//j different
if(dp[i][j]==)continue;
for(t=max(,m-(n-j));t<=j&&t<=m;t++)//j+m should no biger than n or at least (m-(n-j)) should be change
dp[i+][j-t+m-t]=(dp[i+][j-t+m-t]+dp[i][j]*c[j][t]%MOD*c[n-j][m-t]%MOD)%MOD;
}
LL ans=dp[k][];
printf("%lld\n",ans);
}
return ;
}
G:给你一个完全/非完全二叉树求最小的宽度 首先肯定把根节点的两个叶子放在同一侧是最优的 然后让较宽的那一枝在最里面是最优的 以一个节点为例:如果只有一个枝就无限地延伸 ans[x]=ans[a[x][0]] 如果有两个枝的话 相同就宽度+1 不同就取最大的
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
vector<vector<int> >a();
int ans[];
void doit(int x)
{
if(a[x].size()==)
{
ans[x]=;
}
else if(a[x].size()==)
{
doit(a[x][]);
ans[x]=ans[a[x][]];
}
else if(a[x].size()==)
{
doit(a[x][]);
doit(a[x][]);
if(ans[a[x][]]==ans[a[x][]])
ans[x]=ans[a[x][]]+;
else
ans[x]=max(ans[a[x][]],ans[a[x][]]);
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
while(scanf("%d",&n)==)
{
mem(ans,);
for(int i=;i<=n;i++)
a[i].clear();
for(int i=;i<=n-;i++)
{
int x;
scanf("%d",&x);
a[x].push_back(i+);
}
doit();
/*for(int i=1;i<=n;i++)
printf("%d ",ans[i]);
cout << endl;*/
cout << ans[]<<endl;
}
return ;
}
H:几何
题目大意:给你一个三角形的内切圆半径跟外接圆半径,求解出符合条件的三角形,输出三角形的三条边的长度,如果没有符合条件的三角形,输出“NO Solution!”。
解题思路:这个题是SP,既是因为情况不唯一,而且还有精度的误差。
首先能够想到的就是NO Solution!的情况,即当内切圆半径等于1/2外接圆半径时,此时内切圆最大,而三角形为等边三角形,如图。
其次要解决的就是怎么构造三角形的问题,因为解不唯一,所以只要列举出一种解就OK,于是就很容易的想到构造等腰三角形,在最大与最小之间二分等腰三角形的底边长度,解三角形得到答案,如图。
#define sqr(x) (x)*(x) int main()
{
double r, R;
while(~scanf("%lf%lf", &r, &R)){
if(R < *r){
printf("NO Solution!\n");
continue;
}
double left = , right = sqrt(3.0)*R;
while(right-left > eps){
double mid = (left+right)/2.0;
double t = sqrt(sqr(sqrt(sqr(R)-sqr(mid/2.0))+R)+sqr(mid/2.0));
//printf("%lf\n", t);
if(sqr(sqrt(sqr(r)+sqr(t-mid/2.0))+r) + sqr(mid/2.0) - sqr(t) < eps){
right = mid;
}
else {
left = mid;
}
} double p = sqrt(sqr(sqrt(sqr(R)-sqr(left/2.0))+R)+sqr(left/2.0));
printf("%.16lf %.16lf %.16lf\n", p, p, left);
} return ;
} /*Sample test*/
/* */ ZOJ
Summer training #2的更多相关文章
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2016 Multi-University Training Contests
2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 2016 Multi-University Training Contest 1 G. Rigid Frameworks
Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- The Solution of UESTC 2016 Summer Training #1 Div.2 Problem C
Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/C Description standard input/output After ...
- 2012 Multi-University Training Contest 9 / hdu4389
2012 Multi-University Training Contest 9 / hdu4389 打巨表,实为数位dp 还不太懂 先这样放着.. 对于打表,当然我们不能直接打,这里有技巧.我们可以 ...
- 2014 Multi-University Training Contest 9#11
2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others) ...
- 2014 Multi-University Training Contest 9#6
2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...
- 2016 Multi-University Training Contest 1
8/11 2016 Multi-University Training Contest 1 官方题解 老年选手历险记 最小生成树+线性期望 A Abandoned country(BH) 题意: 1. ...
随机推荐
- JavaScript中函数文档注释
/** 方法说明 * @method 方法名 * @for 所属类名 * @param{参数类型}参数名 参数说明 * @return {返回值类型} 返回值说明 */
- Linux服务知识点总结
一.firewalld防火墙 1.firewalld简述 firewalld:防火墙,其实就是一个隔离工具:工作于主机或者网络的边缘.对于进出本主机或者网络的报文根据事先定义好的网络规则做匹配检测,对 ...
- 论文阅读及复现 | Improved Semantic Representations From Tree-Structured Long Short-Term Memory Networks
两种形式的LSTM变体 Child-Sum Tree-LSTMs N-ary Tree-LSTMs https://paperswithcode.com/paper/improved-semantic ...
- mac docker --net=host
Docker 中的 host 模式指定是容器与主机享受相同的 network namespace. host 模式设计出来就是为了性能,但是这却对 docker 的隔离性造成了破坏,导致安全性降低. ...
- python库 使用shutil来删除文件夹时报PermissionError时的解决方案
解决方案: def handle_remove_read_only(func, path, exc): excvalue = exc[1] if func in (os.rmdir, os.remov ...
- Sliding Puzzle
On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square repre ...
- 【环境搭建】Angular (含Hello World)
一.环境安装 1.安装node.js 下载路径:https://nodejs.org/en/download/ 命令行验证: 2.安装ts.cli ts: npm install -g typescr ...
- PAT B1028 人口普查(20)
课本AC代码 #include <cstdio> struct person { char name[10]; int yy, mm, dd; } oldest, youngest, le ...
- union和in哪个效率高
一直都认为是in的效率要高,但是这次确有点蒙圈. SELECT * FROM runinfo WHERE status in (0,2,1,3,4,7,9,10); 这个查询的效率是,经常是1秒多. ...
- dev listbox使用
private void Init() { List<Funcation> data = new List<Funcation>(); data.Add(new Funcati ...