DUT Star Round2
Problems: 开灯问题,问无数次操作之后第n盏灯的状态
Analysis:
cj:平方数有奇数个约数
Tags: Implementation
Problems: 给定一个1..n的全排列,询问区间[l, r]中的数字是否排序后连续
Analysis:
cj:智障的我想了一个及其错误的算法,后来被lucky_ji点醒,if (区间最大值最小值之差 == 区间长度)就好了。。
Return:燃鹅楼上STILL犯了一个有趣的错误,Max-Min+1==Length,当然,区间Max和Min的维护用线段树或者倍增DP就行了
Tags: Data Structure, Dynamic Programming
#include<cstdio>
#include<cstring>
#include<algorithm>
//#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define INF 2000000000
#define Clear(x, Num) memset(x, Num, sizeof(x))
#define Dig(x) ((x>='0') && (x<='9'))
#define Neg(x) (x=='-')
#define G_c() getchar()
#define Maxn 100010
typedef long long ll; int n, a[Maxn], D_min[Maxn][], D_max[Maxn][], m, l, r; inline int gcd(int x, int y) { if (!y) return x; return gcd(y, x%y); }
inline void read(int &x){ char ch; int N=; while ((ch=G_c()) && (!Dig(ch)) && (!Neg(ch))); if (Neg(ch)) { N=-; while ((ch=G_c()) && (!Dig(ch))); } x=ch-; while ((ch=G_c()) && (Dig(ch))) x=x*+ch-; x*=N; }
//inline void Insert(int u, int v) { To[Cnt]=v; Next[Cnt]=Head[u]; Head[u]=Cnt++; } void rmq_Min()
{
int temp=(int)(log((double)n)/log(2.0));
for(int i=;i<n;i++) D_min[i][]=a[i];
for(int j=;j<=temp;j++)
for(int i=;i<n;i++)
if(i+(<<j)<=n) D_min[i][j]=min(D_min[i][j-], D_min[i+(<<(j-))][j-]);
} void rmq_Max()
{
int temp=(int)(log((double)n)/log(2.0));
for(int i=;i<n;i++) D_max[i][]=a[i];
for(int j=;j<=temp;j++)
for(int i=;i<n;i++)
if(i+(<<j)<=n) D_max[i][j]=max(D_max[i][j-], D_max[i+(<<(j-))][j-]);
} int Minimum(int L, int H)
{
int k=(int)(log((double)H-L+)/log(2.0));
return min(D_min[L][k],D_min[H-(<<k)+][k]);
} int Maximum(int L, int H)
{
int k=(int)(log((double)H-L+)/log(2.0));
return max(D_max[L][k],D_max[H-(<<k)+][k]);
} int main()
{
read(n);
for (int i=; i<n; i++) read(a[i]);
rmq_Min(); rmq_Max();
read(m);
for (int i=; i<=m; i++)
{
read(l); read(r); l--; r--;
int Res=Maximum(l, r)-Minimum(l, r)+;
if (Res==r-l+) puts("YES"); else puts("NO");
}
}
Code By Return
C. ACM群日常禁言一万年
Problems: 秒数转换为xdays, hh/mm/ss
Analysis:
Return:模拟,注意输出格式即可
Tags: Implementation
Problems: 构造长度为n的序列{a},使得LCM(a1, a2, ......, an) = a1 + a2 + ...... + an
Analysis:
Return:首先想到找规律,发现n为奇数时每次在后面加上2*6^k, 3*6^k即可,然后在找n为偶数规律的时候发现,易得下列式子
∑(a_i)=Lcm(a_i) <=> 6*∑(a_i)=6*Lcm(a_i) <=> ∑(a_i*6)=6*Lcm(a_i) <=> 1+2+3+∑(a_i*6)(a_i≠1)=6*Lcm(a_i)
从而发现递推通式,然而,本题坑点在于对a_i的限制,然后发现只有在n=20的时候会Max{a_i}>Limit,从而进一步寻找规律可过
Tags: Math
#include<cstdio>
#include<cstring>
#include<algorithm>
//#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define INF 2000000000
#define Clear(x, Num) memset(x, Num, sizeof(x))
#define Dig(x) ((x>='0') && (x<='9'))
#define Neg(x) (x=='-')
#define G_c() getchar()
#define Maxn 10010
typedef long long ll; int n, Cnt;
ll S[Maxn]; inline int gcd(int x, int y) { if (!y) return x; return gcd(y, x%y); }
inline void read(int &x){ char ch; int N=; while ((ch=G_c()) && (!Dig(ch)) && (!Neg(ch))); if (Neg(ch)) { N=-; while ((ch=G_c()) && (!Dig(ch))); } x=ch-; while ((ch=G_c()) && (Dig(ch))) x=x*+ch-; x*=N; }
//inline void Insert(int u, int v) { To[Cnt]=v; Next[Cnt]=Head[u]; Head[u]=Cnt++; } int main()
{
while (scanf("%d", &n)!=EOF)
{
if (n==) { puts("3 2 1"); continue; }
S[]=, S[]=, S[]=, S[]=; Cnt=;
while (Cnt<n)
{
for (int i=; i<=Cnt; i++) if ((S[i]!=) && (S[i]!=)) S[i]*=;
S[++Cnt]=;
}
for (int i=; i<=n; i++) printf("%lld ", S[i]); puts("");
}
}
Code By Return
E.小q与面试题
Problems: 维护一个可以查询最小值的栈
Analysis:
cj: 这种题最适合用STL乱搞了
Tags: Data Structure
#define PRON "e"
#include <set>
#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = + ; stack<int> q;
multiset<int> s; char ch;
inline void read(int & x){
int flag = ;
do {
if (ch == '-')
flag = -;
ch = getchar();
} while (!('' <= ch && ch <= '')); x = ;
do {
x = x * + ch - '';
ch = getchar();
} while ('' <= ch && ch <= ''); x *= flag;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif
s.clear();
while (not q.empty())
q.pop(); int T, a, b, sum = ;
read(T);
while (T --){
read(a);
if (a == ){
read(b);
++ sum;
s.insert(b);
q.push(b);
}
if (a == ){
if (sum == )
puts("ERROR!");
else
printf("%d\n", q.top());
}
if (a == ){
if (sum == )
puts("ERROR!");
else
printf("%d\n", *s.begin());
}
if (a == ){
if (sum == )
puts("ERROR!");
else {
-- sum;
s.erase(s.find(q.top()));
q.pop();
}
}
}
}
Code by cj
Problems: 给定一张n*n的地图,并有m次操作,每次操作为放置炸弹(在砖块上放置视为无效操作),炸弹可以炸掉上下左右最近的砖块,输出最后剩余的砖块数
Analysis:
cj: 直接模拟会Time Limit Exceeded,用row[i]存储第i行的砖块的j坐标,col[j]存储第j行砖块的i坐标。每一次放置炸弹成功后,二分找到前后和左右的砖块并且erase
Tags: Implementation
#define PRON "f"
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; #define lb lower_bound
#define r(y, x) lb(row[y].begin(), row[y].end(), x)
#define c(x, y) lb(col[x].begin(), col[x].end(), y) const int maxn = + ; int n, sum = ;
char s[maxn][maxn];
vector<int> row[maxn], col[maxn]; int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &n);
for (int i = ; i < n; i ++){
scanf("%s", s[i]); for (int j = ; j < n; j ++)
if (s[i][j] == '*')
++ sum;
} for (int i = ; i < n; i ++)
for (int j = ; j < n; j ++)
if (s[i][j] == '*')
row[i].push_back(j); for (int j = ; j < n; j ++)
for (int i = ; i < n; i ++)
if (s[i][j] == '*')
col[j].push_back(i); int q, x, y, pos;
scanf("%d", &q);
while (q --){
scanf("%d %d", &y, &x); if ((not row[y].empty() && *(r(y, x)) == x) && (not col[x].empty() && *(c(x, y)) == y))
continue; if (not row[y].empty()){
-- sum;
if (x < *row[y].begin()){
col[*row[y].begin()].erase(c(*row[y].begin(), y));
row[y].erase(row[y].begin());
}
else if (x > *(row[y].end() - )){
col[*(row[y].end() - )].erase(c(*(row[y].end() - ), y));
row[y].erase(row[y].end() - );
}
else {
-- sum;
pos = r(y, x) - row[y].begin();
col[row[y][pos]].erase(c(row[y][pos], y));
col[row[y][pos - ]].erase(c(row[y][pos - ], y)); row[y].erase(pos + row[y].begin());
row[y].erase(pos - + row[y].begin());
}
} if (not col[x].empty()){
-- sum;
if (y < *col[x].begin()){
row[*col[x].begin()].erase(r(*col[x].begin(), x));
col[x].erase(col[x].begin());
}
else if (y > *(col[x].end() - )){
row[*(col[x].end() - )].erase(r(*(col[x].end() - ), x));
col[x].erase(col[x].end() - );
}
else {
-- sum;
pos = c(x, y) - col[x].begin();
row[col[x][pos]].erase(r(col[x][pos], x));
row[col[x][pos - ]].erase(r(col[x][pos - ], x)); col[x].erase(pos + col[x].begin());
col[x].erase(pos - + col[x].begin());
}
} } printf("%d\n", sum);
}
Code by cj
Problems: 题面描述同最基本的数字“正方形”问题
Tags: Dynamic Programming
DUT Star Round2的更多相关文章
- DUT Star Weekly Contest #3 Problem F Solution
题目链接 问题转化 \[a_i+a_j+(i-j)^2=a_i+i^2+a_j+j^2-2ij\] 令 \(b_i=a_i+i^2\) , 问题化为: 求 \[\max \{b_i+b_j-2ij\} ...
- 【Star CCM+实例】开发一个简单的计算流程.md
流程开发在CAE过程中处于非常重要的地位. 主要的作用可能包括: 将一些经过验证的模型隐藏在流程中,提高仿真的可靠性 将流程封装成更友好的界面,降低软件的学习周期 流程开发实际上需要做非常多的工作,尤 ...
- github中的watch、star、fork的作用
[转自:http://www.jianshu.com/p/6c366b53ea41] 在每个 github 项目的右上角,都有三个按钮,分别是 watch.star.fork,但是有些刚开始使用 gi ...
- [deviceone开发]-Star分享的几个示例
一.简介 这个是star早期分享的几个示例,都非常实用,包括弹出的菜单,模拟支付密码输入等.初学者推荐.也可以直接使用.二.效果图 三.相关下载 https://github.com/do-proje ...
- 时隔一年再读到the star
The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ...
- Github上的Watch和 Star的区别
Github 推出了新的 Notification 系统,更改了原有的 Watch 机制,为代码库增加了 Star 操作.Notification 将接收 Watching 代码库的动态,包括:* I ...
- 纯css3 Star
<style><!--* { box-sizing: border-box; padding: 0px; margin: 0px; } body, html { height: 10 ...
- Got the Best Employee of the year 2015 Star Award
Got "The Best Employee of the year 2015 Star Award" from the company, thanks to all that h ...
- star ccm+ 11.02安装
STAR CCM+是CD-Adapco公司的主打软件,其安装方式较为简单,这里以图文方式详细描述STAR CCM+11.02安装过程. 1 安装准备工作2 正式安装3 软件破解4 软件测试 1 安装准 ...
随机推荐
- [Qt系列] 何处下载,如何安装!
时间:2016.07.29 -------------------------------------------- 其实方法有很多! 我的思路是想独立使用它,不想联合VS. 下载地址:http:// ...
- 修改C# 新建类模板
找到安装路径下的这个文件夹:D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplatesCache\CSh ...
- hive中分号问题
分号是sql的结束符,在hql中亦如此,但是hive对分号的识别没有那么智能,如下: select concat(';','aa') from lhc limit 1; FAILED: Parse E ...
- Android_SQLite版本升级,降级 管理
今天我们主要学习了数据库版本升级对软件的管理操作. 我们手机经常会收到xxx软件升级什么的提醒,你的软件版本更新,同时你的数据库对应的版本也要相应的更新. 数据库版本更新需要主要的问题: 软件的1.0 ...
- CSS预编译器配置-------LESS Sass Stylus webstorm
预编译器配置说明 开头语,发挥CSS预处器的作用是一种很有挑战性的事情.CSS预处器有不同的语言,就有不同的语法和功能. 语法 在使用CSS预处器之前最重要的是对语法的理解,幸运的是,这三种CSS预处 ...
- The remote name could not be resolved问题的解决方法
网站如果绑定了代理ip,内部跳转的时候,就会报The remote name could not be resolved错误,这个错误很难排查,网上也没有多少可参考的例子 现在记录下解决方法,以备参考 ...
- Git 查看某个版本修改了哪些文件
. . . . . 查看某个版本提交了哪些文件,其实就是查看该版本与其上一个版本之间的差异,所以通过 git diff 命令来取得结果,并且对比的是要查看的版本与它的上一个版本的 commit 号. ...
- [原创]迈出NIOS的第一步,HelloNIOS
Altera官方推出NIOS已经很久了,个人感觉C+V代码配合会是后面FPGA使用的一个主流,由C来完成一些对时序要求不高,对功能要求偏高的部分,比如运动控制等:由V来配合时序完成高时序要求的需求以及 ...
- js获取鼠标当前的位置
有时候,我们需要得到窗口拖动或者鼠标移动的距离,此时可以通过计算鼠标前后在页面中的位置来得到想要的结果,下面介绍几个事件属性: 1.客户区坐标位置 鼠标事件都是在浏览器视口中的特定位置上发生的.这个位 ...
- php常用的数组函数
array_change_key_case -- 返回字符串键名全为小写或大写的数组 array_chunk -- 将一个数组分割成多个 array_combine -- 创建一个数组,用一个数组的 ...