题目链接:

http://codeforces.com/contest/724

A. Checking the Calendar
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given names of two days of the week.

Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.

In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.

Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".

Input

The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".

Output

Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).

Examples
input
monday
tuesday
output
NO
input
sunday
sunday
output
YES
input
saturday
tuesday
output
YES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=5e5+10;
string str1,str2;
int check(string s)
{
if(s=="monday")return 0;
else if(s=="tuesday")return 1;
else if(s=="wednesday")return 2;
else if(s=="thursday")return 3;
else if(s=="friday")return 4;
else if(s=="saturday")return 5;
else return 6;
}
int main()
{
cin>>str1>>str2;
int a=check(str1),b=check(str2);
int t=(b-a+7)%7;
if(28%7==t||30%7==t||31%7==t)printf("YES\n");
else printf("NO\n");
return 0;
}
/* 题意: 水; 思路:
水;
*/

  


B. Batch Sort
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a table consisting of n rows and m columns.

Numbers in each row form a permutation of integers from 1 to m.

You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.

You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.

Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.

Output

If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

Examples
input
2 4
1 3 2 4
1 3 4 2
output
YES
input
4 4
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
output
NO
input
3 6
2 1 3 4 5 6
1 2 4 3 5 6
1 2 3 4 6 5
output
YES
#include <bits/stdc++.h>
using namespace std;
int n,m,a[23][23],num[23],flag=1;
int check(int x,int y)
{
for(int i=1;i<=n;i++)
{
int cnt=0;
for(int j=1;j<=m;j++)
{
if(j==x)
{
if(a[i][j]!=y)cnt++;
}
else if(j==y)
{
if(a[i][j]!=x)cnt++;
}
else
{
if(a[i][j]!=j)cnt++;
}
}
if(cnt>2)return 0;
}
return 1;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
{
num[i]=0;
for(int j=1;j<=m;j++)
{
if(a[i][j]!=j)num[i]++;
}
if(num[i]>4)
{
cout<<"NO";
return 0;
}
if(num[i]>2)flag=0;
}
if(flag)
{
cout<<"YES";
return 0;
}
flag=0;
for(int i=1;i<=m;i++)
{
for(int j=i+1;j<=m;j++)
{
if(check(i,j))flag=1;
}
}
if(flag)cout<<"YES";
else cout<<"NO";
return 0;
}
/* 题意: 每行交换最多一次,最后还可以交换两列,问最后每行是否都能变成1,2,...m的排列; 思路: 枚举最后要交换哪两列,然后判断每行是否能在一次变换中变成列交换之前的状态,还有判断不进行列交换的时候;
*/

  


C. Ray Tracing
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle.

Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.

At the moment 0, from the point (0, 0) the laser ray is released in the direction of point (1, 1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1, 1) in exactly one second after the start.

When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.

For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print  - 1 for such sensors.

Input

The first line of the input contains three integers nm and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors.

Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.

Output

Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or  - 1 if this will never happen.

Examples
input
3 3 4
1 1
1 2
2 1
2 2
output
1
-1
-1
2
input
3 4 6
1 1
2 1
1 2
2 2
1 3
2 3
output
1
-1
-1
2
5
-1
input
7 4 5
1 3
2 2
5 1
5 3
4 3
output
13
2
9
5
-1
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=1e18;
const int maxn=1e5+5;
int k,fx[maxn],fy[maxn];
LL dir[4][2]={-1,1,-1,-1,1,1,1,-1};
LL tx[4],ty[4],n,m;
LL gcd(LL a,LL b,LL &x,LL &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
LL ans=gcd(b,a%b,x,y);
LL temp=x;
x=y;
y=temp-a/b*y;
return ans;
}
LL GCD(LL a,LL b)
{
if(!b)return a;
return GCD(b,a%b);
}
LL solve(LL fn,LL fm)
{
LL b=fm-fn;
LL x,y,d;
d=gcd(n,-m,x,y);
if(b%d!=0)return -1;
if(b%m==0)return fn;
LL lcm=abs(n*m/d);
x=x*(b/d);
LL ans=((x*n+fn)%lcm+lcm)%lcm;
if(ans==0)ans=lcm;
return ans;
}
int main()
{
scanf("%I64d%I64d%d",&n,&m,&k);
for(int i=1;i<=k;i++)scanf("%d%d",&fx[i],&fy[i]);
LL hi=n/GCD(n,m)*m;
n*=2;m*=2;
for(int i=1;i<=k;i++)
{
LL ans=inf;
for(int j=0;j<4;j++)
{
LL temp=solve(fx[i]*dir[j][0],fy[i]*dir[j][1]);
if(temp>0&&temp<=hi)ans=min(ans,temp);
}
if(ans==inf)printf("-1\n");
else printf("%I64d\n",ans);
}
return 0;
}
/*
题意:
给出一束光从(0,0)出发,一直到角落才会停,问光到达给出的这些点的最短时间是多少; 思路: 可以发现这些点在平面上镜面对称后得到的点是(2*k*n+-x,2*t*m+-y);然后坐标相等,就是解同余方程了;
范围在(0,lcm(n,m))才是正确的;
*/

  

D. Dense Subsequence
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string s, consisting of lowercase English letters, and the integer m.

One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.

Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.

Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j,  j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.

Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.

Find the lexicographically smallest string, that can be obtained using this procedure.

Input

The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).

The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.

Output

Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.

Examples
input
3
cbabc
output
a
input
2
abcab
output
aab
input
3
bcabcbaccba
output
aaabb
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int m;
char s[maxn],ans[maxn],tep[maxn];
int main()
{
scanf("%d",&m);
scanf("%s",s);
int len=strlen(s),cnt,num;
for(int i=len-1;i>=0;i--)s[i+1]=s[i];
for(char temp='a';temp<='z';temp++)
{
int p=0,flag=1,fp=0;num=0;
for(int i=1;i<=len;i++)
{
if(i<=p+m)
{
if(s[i]<temp)tep[num++]=s[i],p=i;
else if(s[i]==temp)fp=i;
}
else
{
if(fp>p)
{
tep[num++]=s[fp],p=fp;i--;
}
else {flag=0;break;}
}
}
if(flag)
{
for(int i=0;i<num;i++)ans[i]=tep[i];
cnt=num;
break;
}
}
if(cnt==0)
{
char d='z';
for(int i=1;i<=len;i++)d=min(d,s[i]);
cnt=1;
ans[0]=d;
}
sort(ans,ans+cnt);
for(int i=0;i<cnt;i++)printf("%c",ans[i]);
return 0;
}
/*
题意:
每隔m个字符选一个,使得选中的这些字符排序后字典序最小; 思路: 枚举最大的那个字符,遍历一遍,比其小的全要,相等的要当前范围最后一个;
*/

  

codeforces 724的更多相关文章

  1. Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS

    G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...

  2. Codeforces 724 E Goods transportation

    Description 有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流. Sol DP. 这种特殊的图可以DP,把最大流转化成最小割. 最小割 ...

  3. 刷题记录:Codeforces Round #724 (Div. 2)

    Codeforces Round #724 (Div. 2) 20210713.网址:https://codeforces.com/contest/1536. div2明显比div3难多了啊-只做了前 ...

  4. codeforces 724D(贪心)

    题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...

  5. codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)

    题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...

  6. Codeforces 724E Goods transportation(最小割转DP)

    [题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...

  7. 【codeforces 724E】Goods transportation

    [题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. Python基础(一),Day1

    python的安装 python2.x与3.x的部分区别 第一个python程序 变量 字符编码 注释 格式化字符串 用户输入 常用的模块初始 if判断 循环语句 作业 1.python的安装 可以在 ...

  2. django配置fcgi参数解释

    manage.py runfcgi minspare=50 maxspare=200 maxchildren=1000 maxrequests=99999 host=127.0.0.1 port=80 ...

  3. 美丽的阴影(剖析jquery主页)

    jquery Download API Documentation Blog Plugins Browser Support jquery主页第一眼看到的就是这个玻璃渣效果,设计者利用高光和阴影制造出 ...

  4. css设置height 100%

    需要显式设置html,body为100%,body是相对于html,wrapper是相对于body html,body{ height: 100%; } .wrapper{ height: 100; ...

  5. ABAP内表(internal table)有关的系统变量

    SY-TABIX – 内表当前行的索引号.SY-TABIX 的值可以被以下命令修改,但是只适用于索引表(index table).对于哈希表(Hashed table),这个系统变量的值为空或0. A ...

  6. 关于SAP的视图类型

    1 sap的视图的类型sap的视图的类型有五种 Database views (数据库视图):和数据库的视图形同,连接条件是必须自定义. Projection views(投影视图): 用于屏蔽一些字 ...

  7. 穷举法破解 zebrone1.1

    系统 : Windows xp 程序 : zebrone1.1 程序下载地址 :http://pan.baidu.com/s/1boqVcU7 要求 : 编写注册机 使用工具 :OD 可在看雪论坛中查 ...

  8. 安卓开发_浅谈Android动画(二)

    在学习了四个基本动画之后,现在要学习一些更有用的效果 先给出所有的动画xml <?xml version="1.0" encoding="utf-8"?& ...

  9. UIScrollView循环滚动1

    现在基本每一个商业APP都会有循环滚动视图,放一些轮播广告之类的,都是放在UIScrollView之上.假如我要实现N张图片的轮播,我借鉴了几个博文,得到两种方法实现: [第一种]:如下图(图片来源于 ...

  10. iOS设计模式之中介者模式

    中介者模式 基本理解 中介者模式又叫做调停者模式,其实就是中间人或者调停者的意思. 尽管将一个系统分割成许多对象通常可以增加可复用性,但是对象之间的连接又降低了可复用性. 如果两个类不必彼此直接通信, ...