题目链接:

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. Dubbo初探

    Dubbo是什么? 1.阿里巴巴开源项目.2.Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. ps: SOA(面相服务的体系结构) RPC( ...

  2. css3实现switch开关效果

    之前阿里电面的时候问的一个问题,今天抽时间做了个demo. html结构 <div class="container"> <div class="bg_ ...

  3. android sdk无法更新或者更新缓慢的解决方案

    win7安装android sdk老出 Fetching https://dl-ssl.google.com/android/repository/addon .这是android sdk不能连接到谷 ...

  4. SET UPDATE TASK LOCAL

    SET Effect Switches on the local update task. This means that when you specify CALL FUNCTION ... IN ...

  5. 通用javascript方法

    //将序列化成json格式后日期(毫秒数)转成日期格式 YYYY-MM-DD HH:MI:SS function ChangeDateFormat(cellval, type) { var date ...

  6. NSMutable sort排序

    Compare method Either you implement a compare-method for your object: - (NSComparisonResult)compare: ...

  7. sql动态insert向varchar(MAX)中写入据的问题

    sql动态insert向varchar(MAX)中写入据的问题,在写入时出现列无效.后来发现,varchar要加''两个,号才可以 SET @SQL='INSERT INTO '+@TabName+' ...

  8. 基础学习day03---程序结构与控制、函数与数组入门

    一.程序结构   1.顺序结构 2.选择结构 3.循环结构 二.顺序结构 程序至上而下逐行执行,一条语句执行完之后继续执行下一条语句,一直到程序的末尾 三.条件选择结构 选择结构是根据条件的成立与否, ...

  9. LeetCode 2 Add Two Numbers(链表操作)

    题目来源:https://leetcode.com/problems/add-two-numbers/ You are given two linked lists representing two ...

  10. Java基础之子类父类属性覆盖

    当java的子类和父类具有相同名字的属性时,到底java是怎么处理的. 先看代码: package com.joyfulmath.study.field; public class Person { ...